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 <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll fac[100002], invfac[100002], dp[100002];
ll pow(ll x, ll y)
{
ll ans = 1;
ll k = 0;
while((1LL << k ) <= y)
{
if((1LL<<k) & y)
{
ans *= x;
ans %= mod;
}
k++;
x *= x;
x %= mod;
}
return ans;
}
ll comb(ll n, ll k)
{
ll ans = (fac[n] * invfac[k])%mod;
ans = (ans * invfac[n-k])%mod;
return ans;
}
int main()
{
ll n, k; cin >> n >> k;
fac[0] = 1;
for(int i=1;i<=100001;i++) fac[i] = (fac[i-1] * i)%mod;
invfac[100001] = pow(fac[100001], mod - 2);
for(int i=100000;i>=0;i--) invfac[i] = (invfac[i+1] * (i+1))%mod;
ll ans = 0;
dp[1] = 1;
for(ll i=0;i<=k;i++)
{
if(i%2 == 0) ans += (pow(k-i, n) * comb(n+1, i))%mod;
else ans -= (pow(k-i, n) * comb(n+1, i))%mod;
ans %= mod;
}
ans += mod;
ans %= mod;
cout << ans;
}
# | 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... |