首页 > 其他 > 详细

求最小公倍数

时间:2018-08-05 19:27:16      阅读:143      评论:0      收藏:0      [点我收藏+]
public class Gcd {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y = input.nextInt();
        int gcd = Gcd.gcd(x, y);
            System.out.println(gcd+" "+x*y/gcd);
    }

    public static int gcd(int a, int b) {
        int max, min;
        max = (a > b) ? a : b;
        min = (a < b) ? a : b;
        if (max % min != 0) {
            return gcd(min, max % min);
        } else
            return min;
    }
}

 

求最小公倍数

原文:https://www.cnblogs.com/chenxiaobo/p/9426768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!