1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair <int,int> Pii; #define reg register #define pb push_back #define mp make_pair #define Mod1(x) ((x>=P)&&(x-=P)) #define Mod2(x) ((x<0)&&(x+=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
bool Mbe;
const int N=2050,P=998244353;
int n,m,Z; ll k; int A[N],B[N]; ll qpow(ll x,ll k=P-2) { ll res=1; for(;k;k>>=1,x=x*x%P) if(k&1) res=res*x%P; return res; }
int C[N][N]; int rev[N],T[N],IT[N]; void NTT(int n,int *a,int f){ rep(i,0,n-1) if(i<rev[i]) swap(a[i],a[rev[i]]); static int e[N>>1]; for(reg int i=e[0]=1;i<n;i<<=1) { ll t=f==1?T[i]:IT[i]; for(reg int j=i-2;j>=0;j-=2) e[j+1]=t*(e[j]=e[j>>1])%P; for(reg int l=0;l<n;l+=i*2) { for(reg int j=l;j<l+i;++j) { reg int t=1ll*a[j+i]*e[j-l]%P; a[j+i]=a[j]-t,Mod2(a[j+i]); a[j]+=t,Mod1(a[j]); } } } if(f==-1) { ll base=qpow(n); rep(i,0,n-1) a[i]=a[i]*base%P; } }
int Init(int n){ int R=1,cc=-1; while(R<=n) R<<=1,cc++; rep(i,1,R-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<cc); return R; }
int mk1[N],mk2[N]; void FWT(int n,int *A,int *B,int f,int *mk){ static int X[N],Y[N]; rep(i,0,n) { memset(X,0,sizeof X),memset(Y,0,sizeof Y); rep(k,0,i) X[i-k]=(k&1)?P-C[i][k]:C[i][k]; rep(j,0,n) Y[j]=A[j]; int R=Init(n+i+1); NTT(R,X,1),NTT(R,Y,1); rep(j,0,R-1) X[j]=1ll*X[j]*Y[j]%P; NTT(R,X,-1); rep(j,0,n-i) B[i]=(B[i]+1ll*C[n-i][j]*X[i+j])%P; } }
void Solve(int n,int *A,int *mk) { static int X[N],Y[N]; memset(X,0,sizeof X),memset(Y,0,sizeof Y); X[1]=1,FWT(n,X,Y,1,mk); rep(i,0,n) Y[i]=qpow(Y[i],k); memset(X,0,sizeof X); FWT(n,Y,X,2,mk); ll base=qpow(qpow(2,n),P-2); rep(i,0,n) A[i]=X[i]*base%P*C[n][i]%P; }
bool Med; int main(){ freopen("clone.in","r",stdin),freopen("clone.out","w",stdout); rep(i,0,N-1) rep(j,C[i][0]=1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%P; for(int i=1;i<N;i<<=1) { T[i]=qpow(3,(P-1)/i/2); IT[i]=qpow((P+1)/3,(P-1)/i/2); } scanf("%d%d%lld%d",&n,&m,&k,&Z); rep(i,0,n) rep(j,0,m) { if(i*(m-j)+j*(n-i)!=Z) continue; mk1[i]=1,mk2[j]=1; } Solve(n,A,mk1),Solve(m,B,mk2); int ans=0; rep(i,0,n) rep(j,0,m) { if(i*(m-j)+j*(n-i)!=Z) continue; ans=(ans+1ll*A[i]*B[j])%P; } printf("%d\n",ans); }
#include<bits/stdc++.h> using namespace std;
typedef long long ll; #define Mod1(x) ((x>=P)&&(x-=P)) #define Mod2(x) ((x<0)&&(x+=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
const int N=2050,P=998244353;
int n,m,Z; ll k; int A[N],B[N]; ll qpow(ll x,ll k=P-2) { ll res=1; for(;k;k>>=1,x=x*x%P) if(k&1) res=res*x%P; return res; } int C[N][N],W[N][N],mk1[N],mk2[N];
void Solve(int n,int *A,int *mk) { static int X[N],Y[N]; rep(i,0,n) W[0][i]=C[n][i]; rep(i,1,n) { rep(j,0,n) W[i][j]=W[i-1][j]-(j?W[i][j-1]:0),Mod2(W[i][j]); drep(j,n,0) W[i][j]=(j?-W[i][j-1]:0)+W[i][j],Mod2(W[i][j]); }
memset(Y,0,sizeof Y); rep(i,0,n) X[i]=qpow(W[i][1],k); rep(i,0,n) if(mk[i]) rep(j,0,n) Y[i]=(Y[i]+1ll*W[i][j]*X[j])%P; ll base=qpow(qpow(2,n),P-2); rep(i,0,n) A[i]=Y[i]*base%P*C[n][i]%P; }
int main(){ freopen("clone.in","r",stdin),freopen("clone.out","w",stdout); scanf("%d%d%lld%d",&n,&m,&k,&Z); rep(i,0,max(n,m)) rep(j,C[i][0]=1,i) C[i][j]=C[i-1][j-1]+C[i-1][j],Mod1(C[i][j]); rep(i,0,n) rep(j,0,m) { if(i*(m-j)+j*(n-i)!=Z) continue; mk1[i]=mk2[j]=1; } Solve(n,A,mk1),Solve(m,B,mk2); int ans=0; rep(i,0,n) rep(j,0,m) { if(i*(m-j)+j*(n-i)!=Z) continue; ans=(ans+1ll*A[i]*B[j])%P; } printf("%d\n",ans); }
|