题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s1 = scanner.next(); String s2 = scanner.next(); long a = Long.parseLong(s1); long b = Long.parseLong(s2); long c = gcd(a, b); // 两个数的最小公倍数=两个数的乘积÷两个数的最大公约数 System.out.println(a * b / c); } private static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } }