lina_os

Untitled

May 6th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4.  
  5. using namespace std;
  6.  
  7. vector<ll> sieve(ll n){
  8.     vector <bool> isPrime(n + 1, 1);
  9.     isPrime[0] = isPrime[1] = 0;
  10.  
  11.     for(ll i = 2; i * i <= n; i++){
  12.         if(isPrime[i]){
  13.             for(ll j = i * i; j <= n; j += i)
  14.                 isPrime[j] = false;
  15.         }
  16.     }
  17.     vector<ll>v;
  18.     for(int i = 2; i < n + 1; i++){
  19.         if(isPrime[i]) v.push_back(i*i);
  20.     }
  21.  
  22.     return v;
  23. }
  24.  
  25. int main() {
  26.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  27.     int t;
  28.     cin >> t;
  29.     auto v=sieve(1e6);
  30.     set<ll>s(v.begin(), v.end());
  31.     while (t--) {
  32.         ll n;
  33.         cin >> n;
  34.         if (s.find(n)!=s.end()) cout << "YES" << endl;
  35.         else cout << "NO" << endl;
  36.     }
  37.     return 0;
  38. }
  39.  
  40. /*
  41.  */
Advertisement
Add Comment
Please, Sign In to add comment