参考题解:
2023杭电多校5 题解 1 6 7 12 | JorbanS_JorbanS的博客-CSDN博客
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod=998244353;
const ll inf=1<<30;
int T,n,m,a,b;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
ll quickp(ll base,ll pow){
ll r= 1;
while(pow){
if(pow&1) r=r*base%mod;
pow>>=1;
base=base*base%mod;
}
return r;
}
inline int inv(int x){
return quickp(x,mod-2);
}
int fac[N],ifac[N];
inline void init(){
fac[0]=ifac[0]=1;
for(int i=1;i<N;i++)fac[i]=1ll*fac[i-1]*i%mod;
ifac[N-1]=inv(fac[N-1]);
for(int i=N-2;i;i--)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
init();
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&n,&m,&a,&b);
ll res=0;
int k=1ll*a*inv(b-a)%mod;
ll BB=k,CC=1;
for(int i=1;i<=n;i++){
res=(res+C(n,i)*BB%mod*CC%mod)%mod;
BB=1ll*BB*k%mod;
CC=(CC+quickp(i+1,m))%mod;
}res=res*quickp(b-a,n)%mod*inv(quickp(b,n))%mod;
printf("%lld\n",res);
}
return 0;
}