forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_T_primes.cpp
46 lines (41 loc) · 794 Bytes
/
B_T_primes.cpp
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
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
string check(long long int num)
{
if (num < 2)
return "NO";
if (num == 4)
return "YES";
if (num % 2 == 0)
return "NO";
if (ceil(sqrt(num)) == floor(sqrt(num)))
{
if (isprime(sqrt(num)))
return "YES";
return "NO";
}
return "NO";
}
int main()
{
long long int n, num;
cin >> n;
while (n--)
{
cin >> num;
cout << check(num) << endl;
}
}