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

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

算法訓練 最大最小公倍數

2019-11-14 09:10:37
字體:
來源:轉載
供稿:網友

問題描述 已知一個正整數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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东安县| 上虞市| 巩留县| 克东县| 洛扎县| 柏乡县| 唐海县| 台山市| 泽普县| 苍梧县| 张家界市| 漳平市| 莎车县| 丰原市| 扎赉特旗| 太康县| 大冶市| 天台县| 辽宁省| 金塔县| 梁河县| 贵州省| 犍为县| 东安县| 比如县| 广丰县| 于田县| 霍邱县| 和田市| 昆山市| 通山县| 利津县| 定结县| 宣恩县| 沐川县| 宝清县| 石狮市| 子长县| 云林县| 湾仔区| 望江县|