fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long const S = 1000001;
  5. long long p[S];
  6. bool fres = false;
  7. bool tres = true;
  8. int input;
  9. bool isPrime(long long N) {
  10. for (int i = 0; i < S; i++) {
  11. p[i] = fres;
  12. }
  13. for (int i = 2; i * i <= S; i++) {
  14. if (p[i] == fres) {
  15. for (int j = i * i; j <= S; j += i) {
  16. p[j] == tres;
  17. }
  18. }
  19. }
  20. if (p[input] == fres) {
  21. return fres;
  22. }
  23. else {
  24. return tres;
  25. }
  26. }
  27. int main() {
  28. int T;
  29. long long N;
  30. cin >> T;
  31. isPrime(N);
  32. while (T) {
  33. cin >> input;
  34. if (p[input] == fres) {
  35. cout << "YES" << endl;
  36. }
  37. else {
  38. cout << "NO" << endl;
  39. }
  40. T--;
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 11384KB
stdin
5
2
3
4
5
6
stdout
YES
YES
YES
YES
YES