国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

算法訓練 最大最小公倍數

2019-11-11 07:31:27
字體:
來源:轉載
供稿:網友

問題描述 已知一個正整數N,問從1~N中任選出三個數,他們的最小公倍數最大可以為多少。

輸入格式 輸入一個正整數N。

輸出格式 輸出一個整數,表示你找到的最小公倍數。 樣例輸入 9 樣例輸出 504 數據規模與約定 1 <= N <= 106。

(PS:下面是我的代碼。)

package 最大最小公倍數;import java.math.BigInteger;import java.util.Scanner;public class Main { public static BigInteger GCD(BigInteger a , BigInteger b){ BigInteger gcd ; while( !b.equals(BigInteger.ZERO)){ gcd = a.remainder(b); a = b; b = gcd; } gcd = a; return gcd; } public static BigInteger Max_GCM(BigInteger n){ int cnt = 0; BigInteger mul = n; BigInteger j = n.subtract(BigInteger.ONE); while(cnt != 2){ if ( GCD(mul,j).equals(BigInteger.ONE)){ mul = mul.multiply(j); cnt++; } j = j.subtract(BigInteger.ONE); } return mul; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); String str = in.next(); BigInteger n = new BigInteger(str); BigInteger TWO = new BigInteger("2"); if ( n.compareTo(TWO) == 0){ System.out.PRint(2); }else if ( n.compareTo(BigInteger.ONE) == 0){ System.out.print(1); }else if ( n.compareTo(BigInteger.ZERO) <= 0){ System.out.print(0); }else{ BigInteger max = Max_GCM(n); System.out.print(max); } in.close(); }}

(PS:百度了下,由于后臺測試數據出問題,所以判的只有60分) 這里寫圖片描述 (PS:下面是網上的AC代碼,和自己相比,自己簡直low到家了。數學結論不知道,真心不知道那些參加ACM的同學是怎么挺過來的。。。)

#include<iostream>using namespace std;int main(){ long long n,ans; cin>>n; if(n<=2) ans=n; else if(n%2==1) ans=n*(n-1)*(n-2); else { if(n%3==0) ans=(n-1)*(n-2)*(n-3); else ans=n*(n-1)*(n-3); } cout<<ans<<endl; return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临潭县| 广水市| 印江| 南昌县| 汪清县| 讷河市| 徐闻县| 南部县| 宁津县| 莒南县| 三门县| 托里县| 惠来县| 内丘县| 龙海市| 古交市| 崇州市| 石狮市| 泗水县| 巴楚县| 霸州市| 云和县| 凤翔县| 达州市| 咸丰县| 英超| 白银市| 西和县| 霍林郭勒市| 商河县| 抚宁县| 南康市| 江津市| 额敏县| 双城市| 抚顺市| 乌鲁木齐市| 柯坪县| 铜鼓县| 普定县| 舒兰市|