我写了一个gcd TL该。然后调用math内gcd,AC该、、、
思维:它是采取n前面的最小公倍数和n求 1~n的最小公倍数
代码:
import java.util.Scanner;
import java.math.*; public class Main{
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
BigInteger[] s = new BigInteger[102];
s[1] = new BigInteger("1");
s[2] = new BigInteger("2");
int i;
for(i = 3; i < 102; i ++){
s[i] = new BigInteger(((Integer)i).toString());
BigInteger temp = s[i-1].gcd(s[i]);
s[i] = s[i].multiply(s[i-1]).divide(temp);
//System.out.println(s[i]);
}
int n;
while(cin.hasNext()){
n = cin.nextInt();
System.out.println(s[n]);
}
}
}
主题链接: pid=517">http://acm.nyist.net/JudgeOnline/problem.php? pid=517