广义欧拉降幂对于狭义欧拉降幂任然适用
https://blog.csdn.net/qq_37632935/article/details/81264965?tdsourcetag=s_pctim_aiomsg
bzoj388
#include<bits/stdc++.h> using namespace std; #define ll long long ll Pow(ll a,ll b,ll p){ ll res=1; while(b){ if(b%2) res=res*a%p; b>>=1;a=a*a%p; } return res; } ll phi(ll x){ ll res=x,tmp=x; for(ll i=2;i*i<=tmp;i++) if(tmp%i==0){ res=res*(i-1)/i; while(tmp%i==0)tmp/=i; } if(tmp>1) res=res*(tmp-1)/tmp; return res; } ll f(ll p){ if(p==1)return 0; ll q=phi(p); return Pow(2,q+f(q),p); } int main(){ int t;ll p;cin>>t; while(t--){ cin>>p; cout<<f(p)<<'\n'; } }