提交时间:2022-08-08 11:33:34
运行 ID: 54952
#include<bits/stdc++.h> using namespace std; const int M=998244353; typedef long long ll; inline ll Read(){ ll sum=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') sum=sum*10+ch-'0',ch=getchar(); return sum*f; } ll A(ll x){ ll sum=1; for(int i=1;i<=x;++i) sum=sum*i%M; return sum; } int main(){ ll T,n,m; T=Read(); while(T--) { m=Read(),n=Read(); if(m==1) { cout<<A(n+m); continue; } if(m-n==1) { cout<<A(n)*A(m)%M<<'\n'; continue; } if(m==n) { cout<<A(n)*A(m)%M*2%M<<'\n'; continue; } } return 0; }