题解 | 求最小公倍数

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();
        int c = a;                     //存储a的原始值,递归过程中使用。
        System.out.println(gcb(a, b, c));
    }
    public static int gcb(int a, int b, int c) {
        if (a % b ==
                0) {                //a累加过程中永远可以整除自身,所以可以整除b时就是最小公倍数!
            return a;
        }
        return gcb(a + c, b,
                   c);        //a累加自身原始值,例如a=4。  a=4,8,12,16....
    }
}


全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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