Title: 2^ (2^ (2^ (2^ (2^ ...))) MoD p value
SB's question is a series of various disorderly 艹 ...
In fact, one day the brain hole relatively big suddenly want to calculate this thing = = then found this interesting nature = =
Actually +∞ a 2 look scary actually nothing terrible = =
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 10001000using namespace Std;int phi[m],prime[1001001],tot;bool not_prime[m];int phi (int x) {int i,re=x; for (i=2;i*i<=x;i++) if (x%i==0) {re/=i;re*=i-1; while (x%i==0) x/=i; } if (x^1) re/=x,re*=x-1; return re;} int Quick_power (Long long x,int y,int p) {Long long re=1; while (y) {if (y&1) (re*=x)%=p; (x*=x)%=p; y>>=1; } return re;} int Solve (int p) {if (p==1) return 0; int temp=0; while (~p&1) p>>=1,++temp; int Phi_p=phi (p); int Re=solve (phi_p); (re+=phi_p-temp%phi_p)%=phi_p; Re=quick_power (2,re,p)%p; return re<<temp;} int main () {int t,p; for (cin>>t; T t--) {scanf ("%d", &p); printf ("%d\n", Solve (p)); } return 0;}
Bzoj 3884 The correct usage of God and set Euler theorem