您的位置:首页 > 其它

bzoj千题计划279:bzoj4591: [Shoi2015]超能粒子炮·改

2018-03-14 09:52 363 查看
http://www.lydsy.com/JudgeOnline/problem.php?id=4591



最后的式子合并同类项



#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;

const int p=2333;

int C[2334][2334],s[2334][2334];

template<typename T>
void read(T &x)
{
x=0; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}

void pre()
{
C[0][0]=1;
for(int i=1;i<=p;++i)
{
C[i][0]=1;
for(int j=1;j<=i;++j) C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
}
for(int i=0;i<=p;++i)
{
s[i][0]=C[i][0];
for(int j=1;j<=p;++j) s[i][j]=(s[i][j-1]+C[i][j])%p;
}
}

int Lucas(LL n,LL m)
{
if(n<m) return 0;
int ans=1;
for(;m;n/=p,m/=p) ans=ans*C[n%p][m%p]%p;
return ans;
}

int S(LL n,LL k)
{
if(k<0) return 0;
if(n<=p && k<=p) return s
[k];
return (S(n%p,k%p)*Lucas(n/p,k/p)+S(n%p,p-1)*S(n/p,k/p-1))%p;
}

int main()
{
int T;
LL n,k;
pre();
read(T);
while(T--)
{
read(n); read(k);
printf("%d\n",S(n,k));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: