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>
#include <algorithm>
#include <vector>
using namespace std;
long long mod = 1'000'000'007;
long long fact[100001];
long long pow(long long b, long long e)
{
if(e == 0) return 1;
if(e % 2) return (b * pow(b, e-1)) % mod;
else
{
long long temp = pow(b, e/2);
return (temp*temp) % mod;
}
}
long long choose(long long n, long long k)
{
return (((fact[n] * pow(fact[k], mod-2)) % mod) * pow(fact[n-k], mod-2)) % mod;
}
int main()
{
fact[0] = 1;
for(long long i = 1; i <= 100000; i++) fact[i] = (fact[i-1] * i) % mod;
long long N, K;
cin >> N >> K;
long long ans = 0;
for(long long i = 0; i <= K; i++)
{
// long long temp = (mod + (pow(-1, i) * ((choose(N-1, K) * pow(K-i, N)) % mod) ) ) % mod;
long long temp = choose(N+1, i) * pow(K-i, N);
temp = temp % mod;
// cout << choose(N+1, K) << ' ' << pow(K-i, N) << '\n';
// cout << temp << '\n';
if(i % 2 == 0) ans = (ans + temp) % mod;
else ans = (mod + ans - temp) % mod;
}
cout << ans << '\n';
}
# | 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... |