fork(3) download
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int a,b,test;
  7.  
  8. int NWD(int a, int b);
  9.  
  10. int main()
  11. {
  12. cin>>test;
  13.  
  14. for(int i=1;i<=test;i++)
  15. {
  16. cin>>a>>b;
  17. cout<<NWD(a,b)<<endl;
  18. }
  19. return 0;
  20. }
  21.  
  22. int NWD(int a, int b)
  23. {
  24. if(a==b)
  25. {
  26. exit(a);
  27. }
  28.  
  29. do
  30. {
  31. if(a>b)
  32. a=a-b;
  33. else
  34. b=b-a;
  35. }
  36. while(a!=b);
  37. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty