分析:
刚学习了
E
x
E
u
l
e
r
ExEuler
ExEuler 就来写一发
题目让你求
2
2
2...
m
o
d
2^{2^{2...}}mod
222...mod
p
p
p的值
那这个式子 很容易联想到拓展欧拉定理:
a
b
a^b
ab
m
o
d
mod
mod
p
≡
a
(
b
p≡a^{(b}
p≡a(b
m
o
d
^{mod}
mod
φ
(
p
)
+
φ
(
p
)
)
m
o
d
^{φ(p)+φ(p))} mod
φ(p)+φ(p))mod
p
p
p
所以把
φ
φ
φ求出来 一个递归就可以了
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define reg register
using namespace std;
typedef long long ll;
const int Inf=0x7fffffff;
int Phi(int x) //求φ
{
int res=x;
for(int i=2;i*i<=x;i++)
if(x%i==0)
{
res=res/i*(i-1);
while(x%i==0) x/=i;
}
if(x>1) res=res/x*(x-1);
return res;
}
ll ksm(ll x,ll y,ll mod)
{
ll res=1;
while(y)
{
if(y&1) res=(res*x)%mod;
x=(x*x)%mod;
y>>=1;
}
return res;
}
int f(int x){
int n=Phi(x);
return x<=2?0:ksm(2,n+f(n),x);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int p;
scanf("%d",&p);
printf("%d\n",f(p));
}
return 0;
}