Bzoj4591 [Shoi2015]超能粒子炮·改

Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 763  Solved: 281

Description

曾经发明了脑洞治疗仪&超能粒子炮的发明家SHTSC又公开了他的新发明:超能粒子炮·改--一种可以发射威力更加
强大的粒子流的神秘装置。超能粒子炮·改相比超能粒子炮,在威力上有了本质的提升。它有三个参数n,k。它会
向编号为0到k的位置发射威力为C(n,k) mod 2333的粒子流。现在SHTSC给出了他的超能粒子炮·改的参数,让你求
其发射的粒子流的威力之和模2333。

 

Input

第一行一个整数t。表示数据组数。
之后t行,每行二个整数n,k。含义如题面描述。
k<=n<=10^18,t<=10^5

Output

t行每行一个整数,表示其粒子流的威力之和模2333的值。

Sample Input

1
5 5

Sample Output

32

HINT

Source

 

数学问题 组合数

题解留坑待填……

 

因为第39行注释掉的那句,WA了大半个小时

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #define LL long long
 7 using namespace std;
 8 const int mod=2333;
 9 const int mxn=2610;
10 LL read(){
11     LL x=0,f=1;char ch=getchar();
12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
13     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
14     return x*f;
15 }
16 int fac[mxn],inv[mxn];
17 void init(int n){
18     int mxn=n+1;
19     fac[0]=fac[1]=1;inv[0]=inv[1]=1;
20     int i,j;
21     for(i=2;i<mxn;i++){
22         fac[i]=(LL)fac[i-1]*i%mod;
23         inv[i]=((-mod/i*(LL)inv[mod%i])%mod+mod)%mod;
24     }
25     for(i=2;i<mxn;i++)inv[i]=(LL)inv[i-1]*inv[i]%mod;
26     return;
27 }
28 LL C(LL n,LL m){
29     if(n<m)return 0;
30     return (LL)fac[n]*inv[m]%mod*inv[n-m]%mod;
31 }
32 LL lucas(LL n,LL m){
33     if(n<m || m<0)return 0;
34     if(n<mod && m<mod)return C(n,m);
35     return lucas(n/mod,m/mod)*C(n%mod,m%mod)%mod;
36 }
37 int smm[mxn][mxn];
38 LL calc(LL n,LL m){
39 //    if(n<m)return 0;
40     if(n<mod && m<mod)return smm[n][m];
41     return (calc(n/mod,m/mod-1)*smm[n%mod][mod-1]+lucas(n/mod,m/mod)*smm[n%mod][m%mod])%mod;
42 }
43 int main(){
44     int i,j;
45     init(2333+2);
46     for(i=0;i<mod;i++){
47         smm[i][0]=1;
48         for(j=1;j<mod;j++)
49             smm[i][j]=(smm[i][j-1]+C(i,j))%mod;
50     }
51     int T=read();LL n,k;
52     while(T--){
53         n=read();k=read();
54         printf("%lld\n",calc(n,k));
55     }
56     return 0;
57 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6910315.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值