提交时间:2022-08-08 11:29:52
运行 ID: 54916
#include <bits/stdc++.h> using namespace std; #define mod 998244353 #define maxn 10000001 inline int read(){ int x=0;bool f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();} while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); return f?x:-x; } inline int Pow(int x,int y){ int res=1; while(y){ if(y&1) res=1ll*res*x%mod; x=1ll*x*x%mod; y>>=1; } return res; } int fac[10000005]={1},inv[10000005]={1},t,n,m; int main(){ // freopen("line.in","r",stdin); // freopen("line.out","w",stdout); for(int i=1;i<=maxn;i++) fac[i]=1ll*fac[i-1]*i%mod; inv[maxn]=Pow(fac[maxn],mod-2); for(int i=maxn-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod; t=read(); while(t--){ m=read(),n=read(); if(n<m-1) puts("0"); else printf("%d\n",1ll*fac[n]%mod*fac[n+1]%mod*inv[n-m+1]%mod); } return 0; }