Skip to content

Commit 8f98c5d

Browse files
authored
Merge pull request #324 from radensaleh/master
Create T-Primes.cpp
2 parents ff17949 + 8f11453 commit 8f98c5d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bitset>
2+
#include <iostream>
3+
#include <math.h>
4+
using namespace std;
5+
6+
long long n, temp;
7+
bitset<10000005> bs;
8+
9+
void sieve(long long x)
10+
{
11+
bs.set();
12+
bs[0] = bs[1] = 0;
13+
for (long long a = 2; a <= x; a++)
14+
if (bs[a])
15+
for (long long b = a * a; b <= x; b += a)
16+
bs[b] = 0;
17+
}
18+
19+
bool T_Primes(long long x)
20+
{
21+
if (bs[(int)sqrt(x)] && (long long)sqrt(x) * (long long)sqrt(x) == x)
22+
return true;
23+
return false;
24+
}
25+
26+
int main()
27+
{
28+
sieve(10000000);
29+
cin >> n;
30+
while (n--) {
31+
cin >> temp;
32+
if (T_Primes(temp))
33+
cout << "YES\n";
34+
else
35+
cout << "NO\n";
36+
}
37+
}

0 commit comments

Comments
 (0)