fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool is_prime(int m){
  6. if (m < 2) return false;
  7. if (m == 2) return true;
  8. if (m % 2 == 0) return false;
  9. int limit = sqrt(m);
  10. for (int i = 3; i <= limit; i += 2){
  11. if (m % i == 0) return false;
  12. }
  13. return true;
  14. }
  15.  
  16. bool is_concluded(int x, int y){
  17. for (int i = 2; i <= x; i++){
  18. if (is_prime(i)){
  19. if (x % i == 0){
  20. if (y % i != 0) return false;
  21. }
  22. }
  23. }
  24. return true;
  25. }
  26.  
  27. int main() {
  28. int n;
  29. cin >> n;
  30. for (int j = 0; j < n; j++){
  31. int a, b;
  32. cin >> a >> b;
  33. if (is_concluded(a,b))
  34. cout << "TAK" << endl;
  35. else
  36. cout << "NIE" << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
2 10
8 4
1 3
stdout
TAK
TAK
TAK