题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/feb002886427421cb1ad3690f03c4242
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 = getCM(m, n);
System.out.println(result);
}
public static int getCM(int m, int n){
//write your code here......
/**
最小公倍数,由定义知道,其一定是最大值的整数倍,所以第一步先把最大值最小值找到,然后将最大值不断翻倍,当翻倍后的数取余最小值为0时,则说明此数值为最小公倍数。
*/
int max=0, min = 0, i = 1;
if(m > n){max = m; min= n;}
else if(m < n){max = n; min = m;}
else{return m;}
while((max*i) % min != 0){
i++;
}
return max*i;
}
}