令答案=run(2,inf,p)
广义欧拉有
run(2,inf,p)== qpow(2,run(2,inf-1,phi[p])+phi[p],p)
则有代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define en '\n'
#define ll long long
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll maxm =1e7+10;
const ll maxn =5e5+10;
using namespace std;
ll euler(ll x){
ll res=x;
for(ll i=2;i*i<=x;i++){
if(x%i==0){
res=res*(i-1)/i;
}
while(x%i==0){
x/=i;
}
}
if(x>1){
res=res*(x-1)/x;
}return res;
}
ll qpow(ll a,ll b,ll m){
ll res=1;
while(b){
if(b&1)res=(res*a)%m;
a=(a*a)%m;b>>=1;
}return res;
}
ll run(ll m){
if(m==1)return 0;
return qpow(2,run(euler(m))+euler(m),m);
}
signed main() {
ll T;
cin>>T;
while(T--){
int p;
scanf("%d",&p);
cout<<run(p)<<en;
}
return 0;
}