D. Count the Arrays

Description

• each array contains n elements;
• each element is an integer from 1 to m;
• for each array, there is exactly one pair of equal elements;
• for each array a, there exists an index i such that the array is strictly ascending before the i-th element and strictly descending after it (formally, it means that $a_j < a_{j + 1}$, if $j, and $a_j > a_{j + 1}$, if $j \ge i$).

Input
The first line contains two integers n and m ($2 \le n \le m \le 2 \cdot 10^5$).

Output
Print one integer — the number of arrays that meet all of the aforementioned conditions, taken modulo 998244353.

Examples
input
3 4
output
6
input
3 5
output
10
input
42 1337
output
806066790
input
100000 200000
output
707899035
Note
The arrays in the first example are:

• $[1,2,1]$;
• $[1,3,1]$;
• $[1,4,1]$;
• $[2,3,2]$;
• $[2,4,2]$;
• $[3,4,3]$.

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5+10;
const ll mod = 998244353;
ll a[maxn];
ll poww(ll x,ll y){
ll ans=1;
while(y){
if(y&1)    ans=(ans*x)%mod;
x=(x*x)%mod;
y>>=1;
}
return ans;
}//快速幂
ll inv(ll x){
return poww(x,mod-2);
}//逆元
int main()
{
ll n,m;
cin>>n>>m;
if(n==2){
cout<<"0"<<endl;
return 0;
}//如果n为2，此时无解
ll ans=0,mid,er=poww(2,n-3);//ans为答案，mid记录每一次组合数的值
mid=1;ans=er*(n-2)%mod;//我们以i=n-1的值为初始情况，将mid和ans初始化
for(ll i=n;i<=m;i++)
mid=(i-1)*mid%mod*inv(i-n+1)%mod,ans=(ans+mid*er%mod*(n-2))%mod;//每次更新mid（即组合数）和ans，注意这里三个数相乘可能会爆long long，总之能取模就多去几次就行了。这里对应的就是上面的分析
cout<<ans<<endl;
return 0;
}