码迷,mamicode.com
首页 > 其他好文 > 详细

1011 最大公约数GCD

时间:2016-04-03 01:36:07      阅读:130      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!