Advertisement
mickypinata

SMMR-T026: Duck Primes

Jun 1st, 2021 (edited)
1,203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long lli;
  5.  
  6. const int N = 1e6;
  7. const int sqrtN = 1e3;
  8.  
  9. int main(){
  10.  
  11.     vector<bool> isPrime(N + 10, true);
  12.     isPrime[1] = false;
  13.     for(int i = 2; i <= sqrtN; ++i){
  14.         if(isPrime[i]){
  15.             for(int j = i + i; j <= N; j += i){
  16.                 isPrime[j] = false;
  17.             }
  18.         }
  19.     }
  20.  
  21.     int Q;
  22.     scanf("%d", &Q);
  23.     for(int q = 1; q <= Q; ++q){
  24.         lli x;
  25.         scanf("%lld", &x);
  26.         double rootX = sqrt(x);
  27.         int fRootX = (int)rootX;
  28.         if(rootX == fRootX && isPrime[fRootX]){
  29.             cout << "YES\n";
  30.         } else {
  31.             cout << "NO\n";
  32.         }
  33.     }
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement