Ask G's P-%mod,
According to the Fermat theorem, G^sigma (c (n,d)) (d|n)%mod=g^ (Sigma (C (n,d)) (d|n)% (mod-1))%mod,
However, Mod-1 is not a prime number, it can only be used to split it into 4 mass factors, and then to solve the 4 equations respectively, first with the Lucas theorem and Ma Xiaoding to find out the value of 4 prime numbers of Sigma (Num[i]), notice that the enumeration factor d is enumerated to sqrt (n) on it, plus C (N,i) and C (n,n/i),
Finally, according to the Chinese remainder theorem merger: With the expansion of Euclid to find each equation for the ax solution, and then put their value *num[i] add up finally in modulo yige (mod-1), The (Sigma (C (n,d)) (d|n)% (mod-1))%mod answer, Finally, we use the quick power to find out the final answer.
#include <cstdio>#include <cmath>#define LL Long Long#define MOD 999911659ll prime[5]={0,2,3,4679,35617};ll num[5],inver[5];void EXGCD (LLx, LLy, ll &a,ll &b) {if(!y) a=1, b=0;Else{EXGCD (y,x%y, b,a); B-=a*(x/y); }}ll Pow (ll a,ll b,ll p) {ll ans=1, Cnt=a; while(b) {if(b&1) ans= (ans*cnt)%p; Cnt= (CNT*cnt)%p; B=b>>1; }returnAns;} ll C (LLm, ll N,ll p) {if(m<n)return 0;if(m==n)return 1;if(n>m-N) n=m-N; ll ans=1, cm=1, cn=1; for(LL i=0; i<n;i++) cm=cm*(m-I.)%p, CN=CN*(N-i)%p;returnCm*pow(cn,p-2, p)%p;} ll Lucas (LLm, ll N,ll p) {if(!n)return 1;return(Lucas (m/p,n/p. PK*c(m%pN%p, p))%p;} ll get (ll N) {ll lim=sqrt(n) +1; for(intI=1; i<lim;i++)if(n%i==0) { for(intj=1; j<=4; j + +) num[j]= (Num[j]+lucas (N,i,prime[j]))%prime[j];if(I*i<n) for(intj=1; j<=4; j + +) num[j]= (Num[j]+lucas (N,n/i,prime[j]))%prime[j]; } ll Mul=1, ans=0, t; for(intI=1; i<=4; i++) Mul*=Prime[i]; for(intI=1; i<=4; i++) {EXGCD (mul/prime[i],prime[i],inver[i],t);//Because the mul/prime[i here], and prime[i] are coprime, so gcd=1, do not consider*c/d Inver[i]*=Mul/prime[i]; } for(intI=1; i<=4; i++) ans= (Ans+num[i]*inver[i])%(mod-1);return(ans+mod-1)%(mod-1);}intMain () {ll n,g,ans; scanf"%lld%lld", &n,&g);if(mod==g) {printf("0");return 0; } g=g%mod; Ans=pow (G,get (n), MoD);printf("%lld", ans);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"BZOJ1951" [Chinese remainder theorem][sdoi2010] Ancient pig text