SHARE
TWEET

tprime accpted

a guest Jul 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4. long long int prime[1000001];
  5. int main()
  6. {
  7.     ll n,a;
  8.     cin>>a;
  9.     prime[1] = 1;
  10.     for(ll i = 2;i<=1000000;i++)
  11.     {
  12.         if(prime[i] == 0)
  13.         {
  14.             for(ll j = i+i;j<=1000000;j+=i)
  15.             {
  16.                 prime[j] = 1;
  17.             }
  18.         }
  19.     }
  20.     for(ll i=0;i<a;i++)
  21.     {
  22.         cin>>n;
  23.         ll sqr=0;
  24.         sqr = sqrt(n);
  25.         if(sqr*sqr==n&&prime[sqr]==0)
  26.         {
  27.             cout<<"YES"<<endl;
  28.         }
  29.         else
  30.         {
  31.             cout<<"NO"<<endl;
  32.         }
  33.     }
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top