URI -- 1028 (Collectable Cards)

Problem Link

Algorithm used Euclidean GCD (Click the link for Tutorial).  

Solution :


/// Author : shohan
/// Problem Type : Math (GCD)
/// URI -- 1028
#include<stdio.h>
int main()
{
int a,b,c,i,j,temp,temp1,tcase;
while(scanf("%d",&tcase)==1){
for(i=1;i<=tcase;i++){
scanf("%d %d",&a,&b);
if(a<b){
temp1=a;
a=b;
b=temp1;
}
while(a%b!=0){
temp=a;
a=b;
b=temp%b;
}
printf("%d\n",b);
temp=0;
}
}
return 0;
}
view raw URI -- 1028 hosted with ❤ by GitHub

Related Posts: