bzoj4591 【Shoi2015】超能粒子炮·改

來源:互聯網
上載者:User

標籤:pac   scanf   log   zoj   amp   iostream   include   ret   sig   

由Lucas定理C(n,k)=C(n/2333,k/2333)*C(n%2333,k%2333)%2333

則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>#define int long longusing namespace std;const int p=2333;int T,c[p+10][p+10],sum[p+10][p+10];int Lucas(int a,int b){    if(a<0||b<0) return 0;    if(a<p&&b<p) return c[a][b];    return Lucas(a/p,b/p)*c[a%p][b%p]%p;}int cal(int n,int k){    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;}void pre(){    c[0][0]=1;sum[0][0]=1; for(int i=1;i<p;i++) c[i][0]=1,sum[i][0]=1,sum[0][i]=1;    for(int i=1;i<p;i++) for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%p;    for(int i=1;i<p;i++) for(int j=1;j<p;j++) sum[i][j]=sum[i][j-1]+c[i][j];}signed main(){    pre();    scanf("%lld",&T);    while(T--)    {        int n,k;        scanf("%lld%lld",&n,&k);        printf("%lld\n",cal(n,k));    }    return 0;}

 

bzoj4591 【Shoi2015】超能粒子炮·改

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.