#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 3000010
#define M 10000010
using namespace std;
typedef long long ll;
ll t,p,tot;
int prime[N],euler[M],v[M];
void sieve()
{
for(int i=2;i<=10000000;i++)
{
if(!v[i])
{
prime[++tot]=i;
euler[i]=i-1;
}
for(int j=1;j<=tot&&i*prime[j]<=10000000;j++)
{
v[i*prime[j]]=1;
if(i%prime[j]==0)
{
euler[i*prime[j]]=euler[i]*prime[j];
break;
}else
{
euler[i*prime[j]]=euler[i]*(prime[j]-1);
}
}
}
}
ll quick_my(ll x,ll y,ll mod)
{
ll ret=1;
while(y)
{
if(y&1)ret=(ret*x)%mod;
x=(x*x)%mod;
y>>=1;
}
return ret;
}
int check(ll x)
{
while(x%2==0)x/=2;
if(x==1)return 1;
return 0;
}
ll solve(ll x)
{
ll ret=0;
if(check(euler[x]))ret+=euler[x];
else ret+=solve(euler[x])+euler[x];
return quick_my(2,ret,x);
}
int main()
{
sieve();
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&p);
if(p==1){puts("0");continue;}
printf("%lld\n",solve(p));
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wzq_qwq/article/details/48206499