超级最小公倍数
时间限制:8000 ms 内存限制:16384 KB
总提交:1334 (456 users) 正确提交:417 (286 users)
描述
给2个正整数a,b(1<=a,b<=10100),求a和b的最小公倍数。
输入
输入包含多组数据,每组数据一行,包含两个正整数a和b,中间以一个空格隔开。输入以0 0结束。
输出
每组数据输出一行,为a,b的最小公倍数。
样例输入
123 321
123456789 987654321
0 0
样例输出
13161
13548070123626141
/**
* @(#)Main.java
*
*
* @author
* @version 1.00 2008/12/8
*/
import java.math.*;
import java.io.*;
import java.util.*;
public class Main {
public static BigInteger gcd(BigInteger a, BigInteger b) {
BigInteger c;
while(true) {
c = a.mod(b);
if(c.compareTo(BigInteger.ZERO) == 0) break;
a = b;
b = c;
}
return b;
}
public static void main(String[] args) {
BigInteger a, b;
Scanner cin = new Scanner(System.in);
while(cin.hasNext()) {
a = cin.nextBigInteger();
b = cin.nextBigInteger();
if((a.compareTo(BigInteger.ZERO) == 0) &&(b.compareTo(BigInteger.ZERO) == 0)) break;
System.out.println(a.divide(gcd(a, b)).multiply(b));
}
return;
}
}