public class MaximumCommonDivisor {
// 最大公约数
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
// 最小公倍数
public static int gbd(int a, int b) {
return a / gcd(a, b) * b;
}
public static void main(String[] args) {
System.out.println("最小公倍数 :(17,12) = " + gbd(17, 12));// 204
System.out.println("最大公约数 :(17,12) = " + gcd(17, 12));// 1
System.out.println("最小公倍数 :(17,12) = " + gbd(18, 12));// 36
System.out.println("最大公约数 :(17,12) = " + gcd(18, 12));// 6
}
}