提交时间:2022-08-08 11:23:36

运行 ID: 54909

#include<bits/stdc++.h> using namespace std; template<typename T>void in(T &a) { T ans=0; char c=getchar(); for(;c<'0'||c>'9';c=getchar()); for(;c>='0'&&c<='9';c=getchar())ans=ans*10+c-'0'; a=ans; } template<typename T,typename... Args>void in(T &a,Args&...args) { in(a),in(args...); } template<typename T>inline T qpow(T a,T b,T n,T ans=1) { for(a%=n;b;b>>=1)(b&1)&&(ans=(ans*a)%n),a=(a*a)%n; return ans%n; } int t; long long m,n,fac[10000005]={1},inv[10000005]={1}; int main(){ for(long long i=1;i<=10000000;i++)fac[i]=fac[i-1]*i%998244353; inv[10000000]=qpow(fac[10000000],998244351ll,998244353ll); for(long long i=9999999;i>=1;i--)inv[i]=inv[i+1]*(i+1)%998244353; in(t); while(t--){ in(m,n); if(m>n+1)puts("0"); else printf("%lld\n",fac[n]*fac[n+1]%998244353*inv[n-m+1]%998244353); } return 0; }