链接:https://codeforces.ml/contest/1312/problem/D
Your task is to calculate the number of arrays such that:
- each array contains nn elements;
- each element is an integer from 11 to mm;
- for each array, there is exactly one pair of equal elements;
- for each array aa, there exists an index ii such that the array is strictly ascending before the ii-th element and strictly descendingafter it (formally, it means that aj<aj+1aj<aj+1, if j<ij<i, and aj>aj+1aj>aj+1, if j≥ij≥i).
Input
The first line contains two integers nn and mm (2≤n≤m≤2⋅1052≤n≤m≤2⋅105).
Output
Print one integer — the number of arrays that meet all of the aforementioned conditions, taken modulo 998244353998244353.
Examples
input
Copy
3 4
output
Copy
6
input
Copy
3 5
output
Copy
10
input
Copy
42 1337
output
Copy
806066790
input
Copy
100000 200000
output
Copy
707899035
Note
The arrays in the first example are:
- [1,2,1][1,2,1];
- [1,3,1][1,3,1];
- [1,4,1][1,4,1];
- [2,3,2][2,3,2];
- [2,4,2][2,4,2];
- [3,4,3][3,4,3].
代码:
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
long long n,m,s1,s2,ans;
long long qpow(long long a,long long b)
{
long long res=1;
while(b)
{
if(b&1)
{
res=(res*a)%mod;
}
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main ()
{
cin>>n>>m;
s1=1;
s2=1;
for(int i=2;i<=n-2;i++)
{
s1=(s1*2)%mod;
}
for(int i=1;i<=n-1;i++)
{
s2=(s2*(m-i+1))%mod;
s2=(s2*qpow(i,mod-2))%mod;
}
ans=(n-2)*s1%mod*s2%mod;
cout<<ans;
return 0;
}