fork(3) 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) a=a-b;
  11. else b=b-a;
  12. }
  13. while(a!=b);
  14. }
  15.  
  16. int main()
  17. {
  18. int c,d;
  19. int testy;
  20. cin>>testy;
  21. for(int i=0; i<testy;i++){
  22. cin>>c>>d;
  23. if(c<0 || c> 1000000 || d<0 || d> 1000000)
  24. exit (0);
  25. cout<<nwd(c,d)<<endl;
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 16064KB
stdin
5
1 4
4 1
12 48
48 100
123456 653421
stdout
0
0
0
0
0