Skip to content

Commit

Permalink
Merge pull request #324 from radensaleh/master
Browse files Browse the repository at this point in the history
Create T-Primes.cpp
  • Loading branch information
wzhouwzhou authored Oct 20, 2019
2 parents ff17949 + 8f11453 commit 8f98c5d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cplusplus/prime/radensaleh_T-Primes.cpp
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";
}
}

0 comments on commit 8f98c5d

Please sign in to comment.