fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int NWD(int a, int b)
  6. {
  7. while(a!=b)
  8.  
  9. if(a>b)
  10. a-=b;
  11. else
  12. b-=a;
  13.  
  14. return a;
  15. }
  16. int main()
  17. {
  18. int z;
  19. int x;
  20. int N;
  21. cin>> N;
  22. while(N!=0)
  23. {
  24. N--;
  25. cin>>z>>x;
  26. cout<<NWD(z,x)<<endl;
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 3460KB
stdin
5
1 4
4 1
12 48
48 100
123456 653421
stdout
1
1
12
4
3