提交时间:2022-08-08 11:32:25

运行 ID: 54941

#include <bits/stdc++.h> using namespace std; typedef long long ll; const int p=998244353; const int Maxn=1e7+5; int T,n,m; ll C[Maxn]; inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } inline ll Pow(ll x,ll k,ll M) { ll ans=1; while(k) { if(k&1) ans=ans*x%M; x=x*x%M; k>>=1; } return ans%p; } inline ll Comb(ll N,ll M) { if(N==M) return 1; return M>N?0:(C[N]*Pow(C[M],p-2,p))%p*Pow(C[N-M],p-2,p)%p; } inline ll Lucas(ll N,ll M) { return M==0?1:Lucas(N/p,M/p)*Comb(N%p,M%p)%p; } int main() { //freopen("line.in","r",stdin); //freopen("line.out","w",stdout); T=read(); C[1]=1; for(int i=2; i<=Maxn; i++) C[i]=C[i-1]%p*i%p; while(T--) { m=read(),n=read(); if(m>n+1) { puts("0"); continue; } //cout<<C[n]<<'\n'<<Lucas(n+1,m)<<'\n'<<C[m]<<'\n'; printf("%d\n",C[n]*Lucas(n+1,m)%p*C[m]%p); } return 0; }