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
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef double db; typedef unsigned long long ull; typedef pair <int,int> Pii; #define mp make_pair #define pb push_back #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) template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); } template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }
char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int N=1<<21,P=998244353;
int n,c,p,q; 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 w[N],Fac[N+1],Inv[N+1],FInv[N+1],rev[N]; void Init(){ Fac[0]=Fac[1]=Inv[0]=Inv[1]=FInv[0]=FInv[1]=1; rep(i,2,N) { Fac[i]=1ll*Fac[i-1]*i%P; Inv[i]=1ll*(P-P/i)*Inv[P%i]%P; FInv[i]=1ll*FInv[i-1]*Inv[i]%P; } w[N>>1]=1; ll t=qpow(3,(P-1)/N); rep(i,(N>>1)+1,N-1) w[i]=w[i-1]*t%P; drep(i,(N>>1)-1,1) w[i]=w[i<<1]; } int Init(int n){ int R=1,c=-1; while(R<n) R<<=1,c++; rep(i,1,R-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<c); return R; }
void NTT(int n,int *a,int f) { rep(i,1,n-1) if(i<rev[i]) swap(a[i],a[rev[i]]); for(int i=1;i<n;i<<=1) { int *e=w+i; for(int l=0;l<n;l+=i*2) { for(int j=l;j<l+i;++j) { 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) { reverse(a+1,a+n); rep(i,0,n-1) a[i]=1ll*a[i]*Inv[n]%P; } }
int A[N],B[N],C[N];
int main(){ Init(); rep(kase,1,rd()) { n=rd(),p=rd(),q=rd(),p=p*qpow(q)%P,q=P+1-p,c=rd(); int R=Init(n),t=1; rep(i,0,R-1) A[i]=B[i]=C[i]=0; rep(i,0,c-1) { A[i]=1ll*Fac[c-1]*FInv[i]%P*FInv[c-1-i]%P*t%P; t=1ll*t*q%P; } rep(i,0,n-c) B[i]=1ll*Fac[n-c]*FInv[i]%P*FInv[n-c-i]%P; NTT(R,A,1),NTT(R,B,1); rep(i,0,R-1) A[i]=1ll*A[i]*B[i]%P; NTT(R,A,-1);
R=Init(n*2); rep(i,n,R-1) A[i]=0; rep(i,0,R-1) B[i]=0; t=1; rep(i,0,n-1) { t=1ll*t*q%P; A[i]=1ll*A[i]*Fac[i]%P*qpow(P+1-t)%P; } rep(i,0,n) B[n-i]=(i&1)?P-FInv[i]:FInv[i]; NTT(R,A,1),NTT(R,B,1); rep(i,0,R-1) A[i]=1ll*A[i]*B[i]%P; NTT(R,A,-1); rep(i,1,n) printf("%d\n",int(1ll*FInv[n-i]*A[2*n-i]%P*p%P)); } }
|