-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #324 from radensaleh/master
Create T-Primes.cpp
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bitset> | ||
#include <iostream> | ||
#include <math.h> | ||
using namespace std; | ||
|
||
long long n, temp; | ||
bitset<10000005> bs; | ||
|
||
void sieve(long long x) | ||
{ | ||
bs.set(); | ||
bs[0] = bs[1] = 0; | ||
for (long long a = 2; a <= x; a++) | ||
if (bs[a]) | ||
for (long long b = a * a; b <= x; b += a) | ||
bs[b] = 0; | ||
} | ||
|
||
bool T_Primes(long long x) | ||
{ | ||
if (bs[(int)sqrt(x)] && (long long)sqrt(x) * (long long)sqrt(x) == x) | ||
return true; | ||
return false; | ||
} | ||
|
||
int main() | ||
{ | ||
sieve(10000000); | ||
cin >> n; | ||
while (n--) { | ||
cin >> temp; | ||
if (T_Primes(temp)) | ||
cout << "YES\n"; | ||
else | ||
cout << "NO\n"; | ||
} | ||
} |