Hints : You need to check p and (2^p -1) is prime or not . ( 2^p -1) is an odd number. So also check ( 2^p -1) is even or not before prime checking as input is large enough upto 2^33.
#include <bits/stdc++.h>
using namespace std;
long long int isprime(long long int p)
{
long long int i,j,k;
if(p==1)
{
return 0;
}
else if (p==2)
{
return 1;
}
else if (p%2==0)
{
return 0;
}
else
{
for(i=3;i<=sqrt(p);i=i+2)
{
if(p%i==0)
{
return 0;
}
}
}
return 1;
}
int main()
{
long long int t,y,pr,yj,j;
double pd;
//freopen("1180in.txt","r",stdin);
//freopen("1180out.txt","w",stdout);
cin>>t;
for(y=1;y<=t;y++)
{
scanf("%lld,",&pr);
j=pow((double)2,pr)-1;
if(isprime(pr) && isprime(j))
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}
0 comments:
Post a Comment