题解 | #求最小公倍数#

求最小公倍数

https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();

        for (int i = a > b ? a : b; i <= 100000000; i++) {
            if (i % a == 0 && i % b == 0) {
                System.out.println(i);
                System.exit(0);
            }
        }
    }
}

解题思路:

1, 最小公倍数的范围应该小于10000000;

2, 从较大的数开始, 进行遍历, 直到得到最终的结果

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务