链接 https://ac.nowcoder.com/acm/contest/9985/B
思路
打表,得出一个7X7的表,根据行(m相同的情况下)找规律
第一行差分数列可以写成组合数形式C(n, 3),接下来自然而然推出来了
1C(n, 3)
2C(n, 4)
3*C(n, 5)
记得预处理1e6的阶乘,不是5e5,wa了一发,挺可惜的
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e6+5;
const double esp = 1e-6;
const ll mod = 998244353;
int n,m;
ll f[N];
ll qpow(ll a,ll b){
ll ans=1,base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod;
b>>=1;
}
return ans;
}
void init(){
f[1]=1;
f[0]=1;
for(int i=2;i<N;i++) {
f[i]=f[i-1]*i%mod;
}
}
ll cal(ll n,ll m){
if(m>n||m<0||n<0) return 0;
return 1ll*f[n]*qpow(f[m],mod-2)%mod*qpow(f[n-m],mod-2)%mod;
}
void solve(){
scanf("%d %d",&n,&m);
printf("%lld",(m-1)*cal(n+m-1,m+1)%mod);
}
int main(){
int Case=1;
init();
//scanf("%d",&Case);
while(Case--){
solve();
}
return 0;
}