首页 > 其他 > 详细

1011 最大公约数GCD

时间:2016-04-03 01:35:21      阅读:179      评论:0      收藏:0      [点我收藏+]

1011 最大公约数GCD

基准时间限制:秒 空间限制:131072 KB 

输入2个正整数AB,求AB的最大公约数。

Input

2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)

Output

输出AB的最大公约数。

Input示例

30 105

Output示例

15

import java.util.Scanner;
public class Main {
    static int gcd(int a,int b){
        return a%b==0? b:gcd(b,a%b);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int a=sc.nextInt();
            int b=sc.nextInt();
            System.out.println(gcd(a,b));
        }
        sc.close();

    }

}

 

1011 最大公约数GCD

原文:http://www.cnblogs.com/watchfree/p/5348670.html

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