fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. int data, a, b, temp;
  7. cin >> data;
  8.  
  9. for (int i = 0; i < data; ++i)
  10. {
  11. cin >> a >> b;
  12. if(a==b)
  13. {
  14. int counter = 2;
  15. //jeśli bok jest kwadratem, dziel go kolejno przez: 2, 3, 4 ...
  16. // i sprawdź czy będzie podzielny na jak największy kwadrat
  17. while(b%(a/counter)!=0)
  18. counter++;
  19. a = a/counter;
  20. }
  21. else
  22. {
  23. // w przeciwnym wypadku obliczaj NWD modulo aż do 0.
  24. while (b!=0)
  25. {
  26. temp = b;
  27. b = a%b;
  28. a = temp;
  29. }
  30. }
  31. cout << a << endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 4344KB
stdin
Standard input is empty
stdout
Standard output is empty