题解 | #求最小公倍数#
求最小公倍数
http://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
最小公倍数公式(a,b)x[a,b]=ab(a,b均为整数)
一开始看题解中的方法在注释
BigInteger中的gcd是求公约数的:
https://blog.csdn.net/cumt30111/article/details/107796422 https://blog.csdn.net/weixin_30768403/article/details/115119543
import java.math.BigInteger;
import java.util.*;
import java.math.BigInteger.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
BigInteger c = BigInteger.valueOf(a);
BigInteger d = BigInteger.valueOf(b);
BigInteger gcd = c.gcd(d);
Integer g = Integer.parseInt(String.valueOf(gcd));
System.out.println(a * b / g);
// System.out.println(a*b/gcd(a,b));
}
// private static int gcd(int a, int b) {
//
// return b==0?a:gcd(b,a%b);
// }
}