最小公倍数

描述
为何1小时有60分钟,而不是100分钟呢?这是历史上的习惯致使。
但也并不是纯粹的偶然:60是个优秀的数字,它的因子比较多。
事实上,它是1至6的每一个数字的倍数。即1,2,3,4,5,6都是能够除尽60。

咱们但愿寻找到能除尽1至n的的每一个数字的最小整数m.

输入 java

多组测试数据(少于500组)。每行只有一个数n(1<=n<=100). ide

输出输出相应的m。 测试

样例输入 code


2
3
4

样例输出 ip


2
6
12

import java.math.BigInteger;
import java.util.Scanner;

public class Main{

	//返回最小公倍数
	static BigInteger fun(BigInteger a,BigInteger b)
	{
		BigInteger k = a,m,n;
		if(a.compareTo(b)>0){
			m=a;
			n = b;
		}
		else{
			m=b;
			n=a;
		}

		while(n!=BigInteger.ONE){
			k=n;
			if(m.mod(n).equals(BigInteger.ZERO))
				return a.multiply(b).divide(k);
			n=m.mod(n);
			m=k;
		}
		return a.multiply(b);
	}
	static Scanner sc=new Scanner(System.in);
	static BigInteger a[]=new BigInteger[101];
	static{
		a[0]=BigInteger.ONE;
		a[1]=BigInteger.valueOf(1);
		a[2]=BigInteger.valueOf(2);
		int i;
		for(i=3;i<a.length;i++){
			a[i]=fun(a[i-1], BigInteger.valueOf(i));
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		while(sc.hasNext()){
			System.out.println(a[sc.nextInt()].toString());
		}
	}
}