题目:https://loj.ac/problem/6485
( sumlimits_{k=0}^{3}sumlimits_{i=0}^{n}C_{n}^{i}s^{i}a_{k}[4|(i-k)] )
然后就是套路即可。
#include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; ll rdn() { ll ret=0;bool fx=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();} while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar(); return fx?ret:-ret; } const int N=5,mod=998244353; int upt(ll x,int mod){x%=mod;if(x<0)x+=mod;return x;} int pw(int x,ll k) {int ret=1;while(k){if(k&1)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=1;}return ret;} int T,s,a[N],iv4,w[N];ll n; void init() { iv4=pw(4,mod-2); w[0]=1;w[1]=pw(3,(mod-1)/4); w[2]=(ll)w[1]*w[1]%mod; w[3]=(ll)w[2]*w[1]%mod; } int main() { T=rdn();init(); while(T--) { n=rdn();s=rdn();for(int i=0;i<4;i++)a[i]=rdn(); int ans=0; for(int k=0;k<4;k++) { int ret=0; for(int j=0;j<4;j++)ret=(ret+(ll)w[upt(j*(n-k),4)]*pw(s+w[upt(-j,4)],n))%mod; ans=(ans+(ll)a[k]*ret)%mod; } ans=(ll)ans*iv4%mod; printf("%d ",ans); } return 0; }