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