题解 | #小乐乐与欧几里得#
小乐乐与欧几里得
http://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0
根据欧几里得算法
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
long a = in.nextLong();
long b = in.nextLong();
long max = gcb(a,b);
//最小公倍数
long min = a*b/gcb(a,b);
System.out.println(max+min);
}
}
//最大公约数
public static long gcb(long a, long b) {
if (b == 0) return a;
return gcb(b, a%b);
}
}