Guest User

T-Prime

a guest
Nov 5th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. //
  2. // Created by soumil on 11/5/2019.
  3. //
  4.  
  5. #include<iostream>
  6. using namespace std;
  7. #include <cmath>
  8. # define ll long long
  9. int main()
  10. {
  11.     int n;
  12.     cin>>n;
  13.     for(int i=0;i<n;i++)
  14.     {
  15.         int x;
  16.         cin>>x;
  17.         int rootceil =ceil(sqrt(x));
  18.         int rootfloor =floor(sqrt(x));
  19.         if(x==4)
  20.         {
  21.             cout<<"YES"<<endl;
  22.             continue;
  23.         }
  24.         // TO check if the number is a perfect square or not
  25.         if(rootceil != rootfloor)
  26.         {
  27.             cout<<"NO"<<endl;
  28.             continue;
  29.         }
  30.         if((x&1)==0 || x<=3)
  31.         {
  32.             cout<<"NO"<<endl;
  33.             continue;
  34.         }
  35.        
  36.         // Calculate the root and then check if it is prime or not
  37.         int count=0;
  38.         for(int j=3;j*j<=rootceil;j+=2)
  39.         {
  40.             if(rootceil % j==0)
  41.             {
  42.                 count++;
  43.                 break;
  44.             }
  45.         }
  46.         if (count)
  47.         {
  48.             cout<<"NO"<<endl;
  49.         }
  50.         else
  51.         {
  52.             cout<<"YES"<<endl;
  53.         }
  54.     }
  55.     return 0;
  56. }
Add Comment
Please, Sign In to add comment