fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int gra(int a, int b){
  5. while (a!=b){
  6. if (a<b)
  7. b-=a;
  8. else
  9. a-=b;
  10. }
  11. return a+b;
  12. }
  13.  
  14. int main(){
  15. int n, c, d;
  16. cin >> n;
  17. int t[n];
  18. for (int i=0; i<n; i++){
  19. cin >> c >> d;
  20. if (c==d)
  21. t[i]=c+d;
  22. else
  23. t[i]=gra(c, d);
  24. }
  25. for (int i=0; i<n; i++)
  26. cout << t[i] << endl;
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 3460KB
stdin
3
11 1
3 4
6 9
stdout
2
2
6