V-最大公约数 递归

输入2个正整数A,B,求A与B的最大公约数。

Input

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

Output

输出A与B的最大公约数。

Sample Input

30 105
Sample Output
15



#include <iostream>
#include <cstdio>

// 欧几里得算法 很简单记住吧! 如果想了解的话,具体的推论:


 //递归式:gcd(a,b)=gcs(b,a%b);
 //递归边界 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;
}

猜你喜欢

转载自blog.csdn.net/lioncatch/article/details/80645212