import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int m = console.nextInt();
int n = console.nextInt();
int result = getLCM(m, n);
System.out.println(result);
}
public static int getLCM(int m, int n) {
int a = m;
int b = n;
// 计算最大公因数(辗转相除法)
while (b != 0) {
int temp = a % b;
a = b;
b = temp;
}
int gcd = a; // 最大公因数
// 最小公倍数 = m * n / 最大公因数
return (m * n) / gcd;
}
}
我是想使用之前数学基础里面学的直接相乘然后除以最大公因数来写的,但是喵的最大公因数对应的那个代码,循环条件我想错了,然后借助了gpt的力量,嗯懒得自己改了
然后 就酱紫

京公网安备 11010502036488号