题意:
a^p=a%p;则称p为以a为基的素数。给定p与a,求判断在p不为素数的情况下,a^p=a%p是否成立。
#include<iostream>
#define ll long long
using namespace std;
ll mul( ll a,ll b,ll mod )
{
ll ret=0;
while( b>0 )
{
if( b&1 )
ret=(ret+a)%mod;
b>>=1;
a=(a<<1)%mod;
}
return ret;
}
int main()
{
int T;
scanf( "%d",&T );
ll r[64],mod,temp;
int N;
r[1]=4;
while( T-- )
{
scanf( "%d",&N );
mod=1;
mod=mod<<N;
mod-=1;
//printf("%lld\n",mod);
for( int i=2;i<=N-1;i++ )
{
temp=mul(r[i-1],r[i-1],mod);
r[i]=(temp-2)%mod;
}
if( N==2||r[N-1]==0 )
printf( "yes\n" );
else
printf( "no\n" );
}
return 0;
}