## 代码

#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define	irin(i,a,b) for(register int i=(a);i>=(b);--i)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;

int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}

const LL MOD=1234567891;
const int MAXN=130;

int k;
LL s,n,d,inv[MAXN],ff[MAXN],gg[MAXN],hh[MAXN];

inline LL qpow(LL x,LL y){
LL ret=1,tt=x%MOD;
while(y){
if(y&1) ret=ret*tt%MOD;
tt=tt*tt%MOD;
y>>=1;
}
return ret;
}

LL g(LL x){
if(x<=k+3) return gg[x];
LL son=1,mot=1;
rin(i,2,k+3) son=son*(x-i+MOD)%MOD;
rin(i,2,k+3) mot=mot*(1-i+MOD)%MOD;
LL ret=0;
rin(i,1,k+3){
ret=(ret+gg[i]*son%MOD*qpow(mot,MOD-2))%MOD;
son=son*qpow(x-(i+1)+MOD,MOD-2)%MOD*(x-i+MOD)%MOD;
mot=mot*qpow(k+3-i+MOD,MOD-2)%MOD*(MOD-i)%MOD;
}
return ret;
}

LL h(LL x){
if(x<=k+4) return hh[x];
LL son=1,mot=1;
rin(i,2,k+4) son=son*(x-i+MOD)%MOD;
rin(i,2,k+4) mot=mot*(1-i+MOD)%MOD;
LL ret=0;
rin(i,1,k+4){
ret=(ret+hh[i]*son%MOD*qpow(mot,MOD-2))%MOD;
son=son*qpow(x-(i+1)+MOD,MOD-2)%MOD*(x-i+MOD)%MOD;
mot=mot*qpow(k+4-i+MOD,MOD-2)%MOD*(MOD-i)%MOD;
}
return ret;
}

int main(){
while(T--){
ff[0]=0;
rin(i,1,k+3) ff[i]=(ff[i-1]+qpow(i,k))%MOD;
gg[0]=0;
rin(i,1,k+3) gg[i]=(gg[i-1]+ff[i])%MOD;
hh[0]=g(s);
rin(i,1,k+4) hh[i]=(hh[i-1]+g((s+i*d)%MOD))%MOD;
printf("%lld\n",h(n));
}
return 0;
}

/*
5
120 102497463 92989700 20360484
66 105420730 97423975 32388530
95 64109604 78460286 106343540
101 66688000 92566071 49084899
102 120568505 7166048 11911911

948519230
179937457
690200633
382076592
500116309
*/


posted on 2019-02-14 11:46  ErkkiErkko  阅读(92)  评论(0编辑  收藏

• 随笔 - 91
• 文章 - 0
• 评论 - 20