题目链接:传送门
题意:
求解构造的序列(本质不同)的贡献和
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e6+5;
const ll MOD=998244353;
ll n,m,ans,jie[maxn];
ll quick(ll a,ll b){
ll ret=1;
while(b){
if(b&1)ret=ret*a%MOD;
a=a*a%MOD,b>>=1;
}
return ret;
}
ll f(ll _n,ll _m){
ll mu;
mu=jie[_m]*jie[_n-_m]%MOD;
return jie[_n]*quick(mu,MOD-2)%MOD;
}
int main(){
ll i,j,tmp;
jie[0]=jie[1]=1;
for (i=2;i<maxn;i++)jie[i]=jie[i-1]*i%MOD;
while(scanf("%lld%lld",&n,&m)!=EOF){
ans=0;j=m-1;
for (i=1;i<n;i++){
tmp=i*(n-i)%MOD;tmp=tmp*f(j,i)%MOD;ans=(ans+tmp)%MOD;
j++;
}
printf("%lld\n",ans);
}
return 0;
}