显然f(i)是一个k+2项式,g(x)是f(i)的前缀和,则显然其是k+3项式,插值即可。最后要求的东西大胆猜想是个k+4项式继续插值就做完了。注意2p>maxint……
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define int long long #define P 1234567891 #define N 200 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int T,k,a,n,d,v[N],f[N]; int ksm(int a,int k) { int s=1; for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P; return s; } int inv(int a){return ksm(a,P-2);}
int calc(int n,int x) { int ans=0; for (int i=0;i<n;i++) { int u=1;for (int j=0;j<n;j++) if (i!=j) u=1ll*u*(P+i-j)%P; u=1ll*v[i]*inv(u)%P; for (int j=0;j<n;j++) if (i!=j) u=1ll*u*(P+x-j)%P; ans=(ans+u)%P; } return ans; } signed main() { #ifndef ONLINE_JUDGE freopen("bzoj3453.in","r",stdin); freopen("bzoj3453.out","w",stdout); const char LL[]="%I64d\n"; #else const char LL[]="%lld\n"; #endif T=read(); while (T--) { k=read(),a=read(),n=read(),d=read(); memset(v,0,sizeof(v)); for (int i=1;i<=k+2;i++) v[i]=(v[i-1]+ksm(i,k))%P; for (int i=1;i<=k+2;i++) v[i]=(v[i]+v[i-1])%P; for (int i=0;i<=k+3;i++) f[i]=calc(k+3,(a+1ll*i*d)%P); for (int i=1;i<=k+3;i++) f[i]=(f[i]+f[i-1])%P; memcpy(v,f,sizeof(v));cout<<calc(k+4,n)<<endl; } return 0; }