求最大公约数,1<=a,b<=100000000;
#include <stdio.h>
long test(long a,long b)
{ long m,i,j,n;
if ( !(a % b) )
m = b;
else { for( n = 2,i = b / 2 + 2; n < i; n ++)
if( !(b % n) )
{ j = b / n;
if( !(a % j ) )
{ m = j ;
break;
}
}
}
return m;
}
int main()
{ int n,m;
long a,b;
scanf("%d",&m);
for(n = 0; n < m; n ++)
{ scanf("%ld %ld",&a,&b);
if( a > b )
printf("%ld\n",test(a,b));
else
printf("%ld\n",test(b,a));
}
return 0;
}
评论