問題描述 已知一個(gè)正整數(shù)N,問從1~N中任選出三個(gè)數(shù),他們的最小公倍數(shù)最大可以為多少。
輸入格式 輸入一個(gè)正整數(shù)N。
輸出格式 輸出一個(gè)整數(shù),表示你找到的最小公倍數(shù)。 樣例輸入 9 樣例輸出 504 數(shù)據(jù)規(guī)模與約定 1 <= N <= 106。
(PS:下面是我的代碼。)
package 最大最小公倍數(shù);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:百度了下,由于后臺(tái)測(cè)試數(shù)據(jù)出問題,所以判的只有60分)
(PS:下面是網(wǎng)上的AC代碼,和自己相比,自己簡(jiǎn)直low到家了。數(shù)學(xué)結(jié)論不知道,真心不知道那些參加ACM的同學(xué)是怎么挺過來的。。。)
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注