题解 | #求最小公倍数#
求最小公倍数
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); } //公式法:两个数的乘积等于这两个数的最大公约数与最小公倍数的积。 //即:(a,b)*[a,b]=a*b public static int getCM(int m, int n){ if(m%n==0){ return m>n? m:n; }else if(m%2==0&&n%2==0){ return (m*n)/2; }else if(m%3==0&&n%3==0){ return (m*n)/3; }else{ return m*n; } //write your code here...... } }