标签:
import java.util.*; public class GetLCM { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); int mod = a % b; if(mod == 0) System.out.println(a); // int out = getMaxMult(a,b); int result = a*b/out; System.out.println(result); } private static int getMaxMult(int a, int b) { int m = a % b; while (m != 0) { a = b; b = m; m = a % b; } return b; } }
注意:
1、先求出最大公约数,利用两数的乘积除以最大公约数得到最小公倍数
2、考虑两数整除的情况
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/liaction/article/details/47665225