fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int nwd(int a, int b)
  6. {
  7. int moda,modb,nwd;
  8. if(a==b) return a;
  9.  
  10. else if(a>b)
  11. {
  12. int temp;
  13. temp=a;
  14. a=b;
  15. b=temp;
  16. }
  17.  
  18. for(int i=1;i<=a;i++)
  19. {
  20. moda=a%i;
  21. modb=b%i;
  22.  
  23. if(moda == 0 && modb == 0)
  24. {
  25. nwd=i;
  26. }
  27. }
  28. return nwd;
  29. }
  30.  
  31. int main()
  32. {
  33. int a,b,ile;
  34.  
  35. cin>>ile;
  36.  
  37. for(int i=1;i<=ile;i++)
  38. {
  39.  
  40. cin>>a>>b;
  41. if(a<0 || a>1000000 || b<0 || b>1000000) {return 0;}
  42.  
  43. cout<<nwd(a,b)<<endl;
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty