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[n][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 ",S(n,k)); } }