-
Notifications
You must be signed in to change notification settings - Fork 287
/
Copy pathT-Prime.cpp
48 lines (45 loc) · 948 Bytes
/
T-Prime.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
47
48
//Author Tejas K Mukherjee
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(a,b) for(int i=a;i<b;i++)
#define FORE(a,b) for(int i=a;i<=b;i++)
bool perfSquare(long double x)
{
// Find floating point value of
// square root of x.
long double sr = sqrt(x);
// If square root is an integer
return ((sr - floor(sr)) == 0);
}
bool isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
int main()
{
int n;
cin>>n;
while(n--)
{
ll tprime;
cin>>tprime;
if (!perfSquare(tprime))
cout<<"NO"<<'\n';
else
{
if (isPrime(sqrt(tprime)))
cout<<"YES"<<'\n';
else
cout<<"NO"<<'\n';
}
}
return 0;
}