제출 #43980

#제출 시각아이디문제언어결과실행 시간메모리
43980MatheusLealVAsceticism (JOI18_asceticism)C++17
100 / 100
53 ms2236 KiB
#include <bits/stdc++.h>
#define N 200030
#define mod 1000000007
using namespace std;
typedef long long ll;

ll n, m, ans, pot[N], fat[N];

ll Pow(ll x, ll p)
{
	if(!p) return 1LL;

	ll ans = Pow(x, p/2);

	ans = (ans*ans)%mod;

	if(p & 1) return (ans*x)%mod;

	return ans;
}

ll inverse(ll x){
	return Pow(x, mod - 2)%mod;
}

ll Choose(ll a, ll b)
{
	ll B = (fat[b]*fat[a - b])%mod;

	return (fat[a]*inverse(B))%mod;
}

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>m;

	pot[0] = fat[0] = 1;

	m--;

	for(int i = 1; i < N; i++) fat[i] = (i*fat[i - 1])%mod;

	for(int k = 0; k <= m + 1; k++)
	{
		ll sign = (k%2 == 0 ? 1 : -1);

		ans = (ans + ((sign*Choose(n + 1, k)*Pow(m + 1 - k, n))%mod) )%mod;
	}

	cout<<(mod + ans)%mod<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...