最大公约数 |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
Total submit users: 1235, Accepted users: 1112 |
Problem 10178 : No special judgement |
Problem description |
输入两个整数a,b(1≤a,b≤100000000),请编写程序求出他们的最大公约数。 |
Input |
第一个数n表示测试数据的个数,接下来的n行每行有两个整数a b,用空格隔开 |
Output |
输出n行,每行输出对应a,b的最大公约数 |
Sample Input |
3 12 8 25 10 21 63 |
Sample Output |
4 5 21 |
Problem Source |
CSU 1st Contest |
#include<stdio.h>
int euclid(int a,int b)
{
if(b==0)
return a;
else
return euclid(b,a%b);
}
int main()
{
int a,i,j;
int m[100],n[100];
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d %d",&m[i],&n[i]);
}
for(j=0;j<a;j++)
{
printf("%d\n",euclid(m[j],n[j]));
}
return 0;
}