By Lucas theorem C (n,k) =c (n/2333,k/2333) *c (n%2333,k%2333)%2333
Then Ans=σc (n,i), (i<=k)
=c (n/2333,0) *c (n%2333,0) +c (n/2333,1) *c (n%2333,1) +...+c (n/2333,2332)
+c (n/2333,0) *c (n%2333,0) +c (n/2333,1) *c (n%2333,1) +...+c (n/2333,2332)
=∑c (n/2333,j) *sum[n%2333][2332]+c (n/2333,k/2333) *sum[n%2333][k%2333], (0<=j<k/2333)
Cal (N,k) =cal (n/2333,k/2333-1) *sum[n%2333][2332]+lucas (n/2333,k/2333) *sum[n%2333][k%2333]
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#defineint long Longusing namespacestd;Const intp=2333;intt,c[p+Ten][p+Ten],sum[p+Ten][p+Ten];intLucas (intAintb) { if(a<0|| b<0)return 0; if(a<p&&b<p)returnC[a][b]; returnLucas (a/p,b/p) *c[a%p][b%p]%p;}intCalintNintk) { if(k<0)return 0; return(Cal (n/p,k/p-1) *sum[n%p][p-1]+lucas (n/p,k/p) *sum[n%p][k%p])%p;}voidPre () {c[0][0]=1; sum[0][0]=1; for(intI=1; i<p;i++) c[i][0]=1, sum[i][0]=1, sum[0][i]=1; for(intI=1; i<p;i++) for(intj=1; j<=i;j++) c[i][j]= (c[i-1][j-1]+c[i-1][J])%p; for(intI=1; i<p;i++) for(intj=1; j<p;j++) sum[i][j]=sum[i][j-1]+c[i][j];} Signed Main () {pre (); scanf ("%lld",&T); while(t--) { intn,k; scanf ("%lld%lld",&n,&k); printf ("%lld\n", Cal (N,k)); } return 0;}
bzoj4591 "Shoi2015" super-energy particle cannon/change