forked from Tushargupta9800/CSES-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT-Primes.cpp
More file actions
77 lines (71 loc) · 1.41 KB
/
T-Primes.cpp
File metadata and controls
77 lines (71 loc) · 1.41 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
void sieveoferatosthene(lli num, vector<bool> &prime)
{
prime[0] = false;
prime[1] = false;
for (lli p = 2; p * p <= num; p++)
{
if (prime[p] == true)
{
for (lli i = p * p; i <= num; i += p)
{
prime[i] = false;
}
}
}
}
int main()
{
lli num = 1000000;
vector<bool> prime(num + 1, true);
sieveoferatosthene(num, prime);
vector<lli> p;
for (lli i = 0; i < prime.size(); i++)
{
if (prime[i] == true)
{
p.push_back(i);
}
}
unordered_set<int> myset;
// for (lli i = 0; i < p.size(); i++)
// {
// for (lli j = 0; j < p.size(); j++)
// {
// if (i != j)
// {
// myset.insert(p[i] * p[j]);
// }
// }
// }
for (lli i = 0; i < p.size(); i++)
{
myset.insert(p[i]);
}
lli t;
//cout << "hello" << endl;
cin >> t;
while (t--)
{
lli x;
cin >> x;
lli sq = sqrt(x);
if (sq * sq == x)
{
if (prime[sq])
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
else
{
cout << "NO" << endl;
}
}
}