Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int N = 1e6;
- const int sqrtN = 1e3;
- int main(){
- vector<bool> isPrime(N + 10, true);
- isPrime[1] = false;
- for(int i = 2; i <= sqrtN; ++i){
- if(isPrime[i]){
- for(int j = i + i; j <= N; j += i){
- isPrime[j] = false;
- }
- }
- }
- int Q;
- scanf("%d", &Q);
- for(int q = 1; q <= Q; ++q){
- lli x;
- scanf("%lld", &x);
- double rootX = sqrt(x);
- int fRootX = (int)rootX;
- if(rootX == fRootX && isPrime[fRootX]){
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement