求最小公倍数
求最小公倍数
http://www.nowcoder.com/questionTerminal/22948c2cad484e0291350abad86136c3
import java.util.Scanner;
public class Main {
private int gcd(int a, int b) {
if (b == 0) return a;
return a % b == 0 ? b : gcd(b, a%b);
}
private int lcm(int a, int b) {
int gcd = gcd(a, b);
return a / gcd * b;
}
public Main() {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int a = in.nextInt();
int b = in.nextInt();
int res = lcm(a, b);
System.out.println(res);
}
}
public static void main(String[] args) {
Main solution = new Main();
}
}
查看6道真题和解析