【题解】P17064 [JRKSJ R10 热身赛] Infinite Strife,
TallBanana
·
·
题解
https://www.luogu.com.cn/problem/P17064
考虑 $(1+x+x^2)^{11}\equiv 1+x^{11}+x^{22}\pmod {11}$。
那么分解 $n$ 为 $11$ 进制 $n=\sum_{i} \alpha_i11^{i}$,则可以表示为 $a_n=[x^n]\prod_{i=0} (1+x^{11^i}+x^{2\times 11^i})^{\alpha_i}$。
考虑 $0\le \alpha_i\le 10$,设 $(1+x^{11^i}+x^{2\times 11^i})^{\alpha_i}$ 选择了 $x^{\beta_i\times 11^i}$ 这一项进行贡献,那么有 $0\le \beta_i\le 2\alpha_i$。要求 $\sum_{i} \beta_i11^i=\sum_i \alpha_i 11^i$。
考虑上式在 $\bmod 11$ 意义下是 $\beta_0\equiv \alpha_0 \pmod {11}$。发现根据 $\beta_0$ 的范围,可以得到 $\beta_0=\alpha_0$。
那么可以同时去掉最低位然后归纳证明。于是 $\forall i,\beta_i=\alpha_i$。
可以预处理一个表 $F_{i}$ 表示 $\alpha=i$ 时的方案数,则 $a_n$ 可以通过对 $n$ 分解质因数后得到是 $\prod_i F_{\alpha_i}$。
考虑 $\prod_{i=1}^{n} {a_i}^{\binom{n-i+c-1}{c-1}}=\prod_{d=0}^{10} (F_{d})^{C(d)}$,其中 $C(d)$ 表示所有 $i$ 11 进制分解后数位是 $d$ 的个数乘上 $\binom{n-i+c-1}{c-1}$ 之和。
对于每个 $C(d)$,拆位处理,那么每一位是类似求很多个组合数上指标区间和。$\sum_{i=l}^{r} \binom{i+c-1}{c-1}=\binom{r+c}{c}-\binom{l-1+c}{c}$。
每个都是形如 $\binom{11^{k}i+b+c}{c}$,注意是在 $\bmod 10$ 意义下,需要 CRT 合并。
根据卢卡斯定理,显然有循环节,且是 $O(c)$ 级别的。
复杂度大概是 $O(T11c(\log_5{c})(\log_{11} n))$,可以通过。
::::success[code]
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
const int N=11,M=2e5+10,P=11;
LL T,n,c,C[N][N],f[N],crt[2][5],zsw[M];
LL lqs(LL a,LL b,const LL &P)
{
if(P==2) return (a&b)==b;
if(~zsw[a]) return zsw[a];
LL res=1,A=a;
while(a&&b) res=res*C[a%P][b%P]%P,a/=P,b/=P;
return zsw[A]=res;
}
struct state { LL n,x,cir; };
map<state,LL> mem;
bool operator <(state a,state b)
{
if(a.cir!=b.cir) return a.cir<b.cir;
if(a.x!=b.x) return a.x<b.x;
return a.n<b.n;
}
LL gcd(LL a,LL b) { return !b?a:gcd(b,a%b); }
LL zxz(LL n,LL x,const LL &P)
{
for(int i=0;i<P;i++)
for(int j=0;j<=i;j++)
C[i][j]=(!j||j==i?1:(C[i-1][j-1]+C[i-1][j])%P);
LL cir=1;
while(cir<=c) cir*=P;
LL ful=0,res=0;
state X={n%gcd(x,cir),gcd(x,cir),cir};
if(mem.find(X)==mem.end())
{
for(int i=0;i<cir;i++) ful=(ful+lqs(n%cir-(x%cir)*i%cir+cir+c,c,P))%P;
mem[X]=ful;
}
else ful=mem[X];
res=ful*(n/x/cir)%P;
n=n%((__int128)cir*x);
for(int i=0;i<=n/x;i++)
res=(res+lqs(n%cir-(x%cir)*i%cir+cir+c,c,P))%P;
return res;
}
LL comb(LL n,LL x) { return crt[zxz(n,x,2)][zxz(n,x,5)]; }
LL cnt(LL d)
{
LL res=0;
for(LL i=0,p=1;p<=n;p*=11,i++)
{
if(n>=d*p) res=(res+comb(n-d*p,11*p))%10;
if(n>=(d+1)*p) res=(res-comb(n-(d+1)*p,11*p)+10)%10;
}
return res;
}
void solve()
{
memset(zsw,-1,sizeof(zsw));
mem.clear();
scanf("%llu%llu",&n,&c);
LL ans=1;
for(int i=0;i<P;i++)
{
LL pw=cnt(i);
while(pw--) ans=ans*f[i]%P;
}
printf("%llu\n",ans);
}
int main()
{
for(int i=0;i<P;i++) crt[i%2][i%5]=i;
for(int i=0;i<N;i++)
for(int j=0;j<=i;j++)
C[i][j]=(!j||j==i?1:(C[i-1][j-1]+C[i-1][j])%P);
for(int i=0;i<N;i++)
{
for(int j=0;j<=i/2;j++) f[i]+=C[i][j]*C[i-j][j];
f[i]%=P;
}
scanf("%llu",&T);
while(T--) solve();
return 0;
}
```
::::