输入2个正整数A,B,求A与B的最大公约数。
Input
2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)
Output
输出A与B的最大公约数。
Sample Input
30 105Sample Output
15
#include <iostream>
#include <cstdio>
// 欧几里得算法 很简单记住吧! 如果想了解的话,具体的推论:
//递归边界 gcd(a,0);
int gco(int a,int b)//找出最大公因数
{
if(b==0)
return a;
else return gco(b,a%b);
}
int main() {
int a, b;
scanf("%d%d",&a,&b);
int temp=gco(a,b);
printf("%d",temp);
return 0;
}