题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
辗转相除法求出最大公约数,再利用最大公约数求出最小公倍数。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a/new Main().gcd(a,b)*b);
}
int gcd(int a, int b){
return b ==0?a:gcd(b,a%b);
}
}
哔哩哔哩公司氛围 723人发布
