標籤:
公式恐懼症患者膜了半天題解QAQ
具體過程見網上其他題解吧>_<
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #define ll long long 6 #define MOD(x) x-=x>=modd?modd:0 7 using namespace std; 8 const int modd=2333; 9 int c[modd][modd],sum[modd][modd];10 ll n,k;11 12 13 14 inline int lucas(ll a,ll b){15 if(a<b)return 0;16 if(a<modd&&b<modd)return c[a][b];17 return c[a%modd][b%modd]*lucas(a/modd,b/modd)%modd;18 }19 int calc(ll n,ll k){20 if(k<0)return 0;21 return (calc(n/modd,k/modd-1)*sum[n%modd][2332]+lucas(n/modd,k/modd)*sum[n%modd][k%modd])%modd;22 }23 inline void prerun(){24 register int i,j;25 for(i=0;i<modd;i++)c[i][0]=sum[i][0]=sum[0][i]=1;26 for(i=1;i<modd;i++)27 for(j=1;j<=i;j++)28 c[i][j]=c[i-1][j]+c[i-1][j-1],MOD(c[i][j]),29 sum[i][j]=sum[i][j-1]+c[i][j],MOD(sum[i][j]);30 for(i=1;i<modd;i++)for(j=i+1;j<modd;j++)sum[i][j]=sum[i][j-1];31 }32 int main(){33 prerun();int T;34 for(scanf("%d",&T);T;T--)35 scanf("%lld%lld",&n,&k),printf("%d\n",calc(n,k));36 }37
View Code
[bzoj4591] [Shoi2015]超能粒子炮·改