Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- vector<ll> sieve(ll n){
- vector <bool> isPrime(n + 1, 1);
- isPrime[0] = isPrime[1] = 0;
- for(ll i = 2; i * i <= n; i++){
- if(isPrime[i]){
- for(ll j = i * i; j <= n; j += i)
- isPrime[j] = false;
- }
- }
- vector<ll>v;
- for(int i = 2; i < n + 1; i++){
- if(isPrime[i]) v.push_back(i*i);
- }
- return v;
- }
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t;
- cin >> t;
- auto v=sieve(1e6);
- set<ll>s(v.begin(), v.end());
- while (t--) {
- ll n;
- cin >> n;
- if (s.find(n)!=s.end()) cout << "YES" << endl;
- else cout << "NO" << endl;
- }
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment