最大公约数GCD

输入2个正整数A,B,求A与B的最大公约数。
Input
2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)
Output
输出A与B的最大公约数。
Input示例
30 105
Output示例
15
李陶冶 (题目提供者)
 
C++的运行时限为:1000 ms ,空间限制为:131072 KB
代码实现:
1 #include<cstdio>
2 int a,b,c,ret=1;
3 inline int gcd(int x,int y){return x%y==0?y:gcd(y,x%y);}
4 int main(){
5     scanf("%d%d",&a,&b);
6     printf("%d\n",gcd(a,b));
7     return 0;
8 }

题目来源:51Nod

posted @ 2017-02-07 07:59  J_william  阅读(329)  评论(0编辑  收藏  举报