fork(1) download
  1. # include<stdio.h>
  2. int a[250];
  3. int gcd(int num,int temp)
  4. { if(temp==0)
  5. return num;
  6. else return gcd(temp,num%temp);}
  7. int main(void)
  8. { int num,i,temp,t=0,n=0,cases,chk=1;
  9. scanf("%d",&cases);
  10. while(cases--)
  11. {char c,w;
  12. t=0;
  13. n=0;
  14. chk=1;
  15. scanf("%d",&num);
  16. w=getchar();
  17. while((c=getchar())!='\n')
  18. a[n++]=c-48;
  19. temp=a[t];
  20. t++;
  21. while(t<n)
  22. { if(num==0)
  23. { for(i=0;i<n;++i)
  24. printf("%d",a[i]);
  25. printf("\n");
  26. chk=0;
  27. break;
  28. } else if(temp<num)
  29. { temp=temp*10;
  30. temp+=a[t];
  31. t++;}
  32. else if(temp==num)
  33. {temp=a[t];
  34. t++;}
  35. else if(temp>num)
  36. {temp=temp%num;}}
  37. if(chk==1)
  38. {if(temp>num)
  39. temp=temp%num;
  40. else if(temp==num)
  41. temp=0;
  42. t=gcd(num,temp);
  43. printf("%d\n",t);
  44. }}
  45. return(0);}
Runtime error #stdin #stdout 0.01s 2684KB
stdin
3
10000 100000000000000000000000000000010
40000 200000000000000000000000000000000
40000 40000
stdout
Standard output is empty