fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. bool isPrime(long long x);
  7.  
  8. int main() {
  9. int t;
  10. cin >> t;
  11. while (t--) {
  12. long long x, k;
  13. cin >> x >> k;
  14.  
  15. if (k == 1) {
  16. if (isPrime(x)) {
  17. cout << "YES" << endl;
  18. } else {
  19. cout << "NO" << endl;
  20. }
  21. }
  22. else if (x == 1 && k == 2) {
  23. cout << "YES" << endl;
  24. }
  25. else {
  26. cout << "NO" << endl;
  27. }
  28. }
  29. return 0;
  30. }
  31.  
  32. bool isPrime(long long x) {
  33. if (x < 2) return false;
  34. for (long long i = 2; i * i <= x; i++) {
  35. if (x % i == 0) return false;
  36. }
  37. return true;
  38. }
Success #stdin #stdout 0.01s 5320KB
stdin
4
52 3
6 7
7 1
1 7
stdout
NO
NO
YES
NO