# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171940 | arnold518 | Asceticism (JOI18_asceticism) | C++14 | 21 ms | 2040 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
const ll MOD = 1e9+7;
int N, K;
ll mypow(ll x, ll y)
{
if(y==0) return 1;
if(y%2) return mypow(x, y-1)*x%MOD;
ll t=mypow(x, y/2);
return t*t%MOD;
}
ll inv(ll x) { return mypow(x, MOD-2); }
ll fact[MAXN+10], invfact[MAXN+10];
ll comb(ll n, ll r) { return fact[n]*invfact[r]%MOD*invfact[n-r]%MOD; }
int main()
{
int i, j;
scanf("%d%d", &N, &K);
fact[0]=1;
for(i=1; i<=N+5; i++) fact[i]=fact[i-1]*i%MOD;
invfact[N+5]=inv(fact[N+5]);
for(i=N+5; i>=1; i--) invfact[i-1]=invfact[i]*i%MOD;
ll ans=0;
for(i=0; i<=K; i++)
{
if(i%2) ans-=mypow(K-i, N)*comb(N+1, i)%MOD;
else ans+=mypow(K-i, N)*comb(N+1, i)%MOD;
ans%=MOD;
ans+=MOD;
ans%=MOD;
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |