欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CodeForces - 1312D Count the Arrays (组合数,方案数)

程序员文章站 2022-06-05 13:42:04
...

????‍???? ????‍???? ????‍????

CodeForces - 1312D Count the Arrays (组合数,方案数)然后套上逆元计算组合数和快速幂就行了

const int MOD = 998244353;
ll fac[MAXN];
void init()
{
	fac[0] = 1;
	for (ll i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % MOD;
}
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (!b)
	{
		x = 1,y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll inv(ll a, ll n)
{
	ll x, y;
	exgcd(a, n, x, y);
	return (x + n) % n;
}
ll C(ll n, ll m){return fac[n] * inv(fac[m] * fac[n - m] % MOD, MOD) % MOD;}
ll qpow(ll a,ll b)//a^b//快速幂
{
    if(b==0) return 1;
    a%=MOD;
    ll ans=1,temp=a;
	while(b)
	{
		if(b&1)	 ans=(ans*temp)%MOD;
		temp=(temp*temp)%MOD;
		b>>=1;
	}
	return ans%MOD;
}
void solve()
{
    init();
    ll n,m;cin>>n>>m;
    if(n==2) cout<<0<<endl;
    else cout<<((C(m,n-1)%MOD)*(n-2)%MOD)*(qpow(2,n-3)%MOD)%MOD<<endl;
}