古代猪文
题目
解析
前置芝士:欧拉定理推论,ExLucas或CRT+Lucas
化简题意:求
g
∑
d
∣
n
C
n
d
(
m
o
d
999911659
)
g^{\sum_{d|n}C_n^d}(\mod 999911659)
g∑d∣nCnd(mod999911659)
由欧拉定理推论得
g
∑
d
∣
n
C
n
d
m
o
d
999911658
(
m
o
d
999911659
)
g^{\sum_{d|n}C_n^d\mod 999911658}(\mod 999911659)
g∑d∣nCndmod999911658(mod999911659)
到这一步,ExLucas可以直接求,CRT+Lucas还要再分解一下:
999911658
=
2
∗
3
∗
4679
∗
35617
999911658=2*3*4679*35617
999911658=2∗3∗4679∗35617
于是Lucas算出来套CRT板子
{
x
≡
∑
d
∣
n
C
n
d
(
m
o
d
m
1
)
x
≡
∑
d
∣
n
C
n
d
(
m
o
d
m
2
)
x
≡
∑
d
∣
n
C
n
d
(
m
o
d
m
3
)
x
≡
∑
d
∣
n
C
n
d
(
m
o
d
m
4
)
\left\{\begin{aligned}x\equiv\sum_{d|n}C_n^d(\mod m_1)\\x\equiv\sum_{d|n}C_n^d(\mod m_2)\\x\equiv\sum_{d|n}C_n^d(\mod m_3)\\x\equiv\sum_{d|n}C_n^d(\mod m_4)\\ \end{aligned}\right.
⎩⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎧x≡d∣n∑Cnd(modm1)x≡d∣n∑Cnd(modm2)x≡d∣n∑Cnd(modm3)x≡d∣n∑Cnd(modm4)
求出x后快速幂一下,这题就结束了
记得特判
999911659
∣
g
999911659\mid g
999911659∣g
code:
#include<cstdio>
#define int long long
#define mod 999911658
using namespace std;
int n,g,a[5],b[5]={0,2,3,4679,35617},c[5],jc[36000],j;
inline int pow(int x,int y,int z){int q=1;for(;y;y>>=1,x=x*x%z)if(y&1)q=q*x%z;return q;}
inline void j_c(int p){jc[0]=1;for(int i=1;i<=p;++i)jc[i]=jc[i-1]*i%p;}
inline int C(int x,int y,int p){return (x>y)?0:(jc[y]*pow(jc[x],p-2,p)%p*pow(jc[y-x],p-2,p)%p);}
inline int L(int x,int y,int p){return (x>y)?0:(y?(C(x%p,y%p,p)*L(x/p,y/p,p)%p):1);}
inline int CRT(){int ans=0;for(int i=1;i<=4;++i)ans=(ans+c[i]*a[i]%mod*pow(c[i],b[i]-2,b[i]))%mod;return ans;}
signed main()
{
scanf("%lld%lld",&n,&g);
if(g%999911659==0){putchar('0');return 0;}
for(int i=1;i<=4;++i)
{
j_c(b[i]);
c[i]=mod/b[i];
for(j=1;j*j<n;++j)if(!(n%j))a[i]=(a[i]+L(j,n,b[i])+L(n/j,n,b[i]))%b[i];
if(j*j==n)a[i]=(a[i]+L(j,n,b[i]))%b[i];
}
printf("%lld",pow(g,CRT(),999911659));
return 0;
}