-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path230B.cpp
More file actions
executable file
·47 lines (39 loc) · 835 Bytes
/
230B.cpp
File metadata and controls
executable file
·47 lines (39 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Problem Code: 230B
#include <iostream>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
void t_primes(int n, vector<int64_t>& x) {
int mxN = 1e6;
set<int64_t> primes;
vector<bool> is_prime(mxN + 1, true);
// sieve of eratosthenes
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= mxN; i++) {
if (!is_prime[i])
continue;
for (int j = i * i; j <= mxN; j += i)
is_prime[j] = false;
}
// list of primes
for (int i = 2; i <= mxN; i++)
if (is_prime[i])
primes.insert(i);
for (int i = 0; i < n; i++) {
int64_t y = sqrt(x[i]);
if (y > 1 && y * y == x[i] && primes.count(y))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
int main() {
int n;
cin >> n;
vector<int64_t> x(n);
for (int i = 0; i < n; i++)
cin >> x[i];
t_primes(n, x);
return 0;
}