我自己写了一个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]); } } }题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=517
原文地址:http://blog.csdn.net/shengweisong/article/details/39896307