题目描述:
解题思路:
欧几里得算法
代码:
public class Main { public static void main(String[] args) { System.out.println(gcd(12, 6)); System.out.println(lcm(3,7)); } public static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } public static int lcm(int x, int y) { return (x * y) / (gcd(x, y)); } }