#include<stdio.h>
int main(){
int i,a,b,ans;
while(scanf("%d %d",&a,&b)==2){
ans=gcd(a,b);
printf("%d\n",ans);
}
return 0;
}
int gcd(int a,int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
#include
int main(){
int i,a,b,ans;
while(scanf("%d %d",&a,&b)==2){
ans=gcd(a,b);
printf("%d\n",ans);
}
return 0;
}
int gcd(int a,int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
#include<stdio.h>
int main()
{
int a,b;
while(scanf(" %d %d",&a,&b)!=EOF)
printf("%d\n",gcd(a,b));
return 0;
}
int gcd(int a,int b)
{
if(a==b)
return a;
if (a>b)
return gcd(a%b,b);
else
return gcd(b%a,a);
}
和我差不多解法,缺點是遞迴好慢啊 QQ
#include<stdio.h>
int main()
{
int a,b;
while(scanf(" %d %d",&a,&b)!=EOF)
printf("%d\n",gcd(a,b));
return 0;
}
int gcd(int a,int b)
{
if(a==0)
return b;
if(a==b)
return a;
if (a>b)
return gcd(a%b,b);
else
return gcd(b%a,a);
}
修正一下,剛剛忘了a==0要終止遞迴 囧