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>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MOD = (int) 1e9 + 7;
inline int lgput(int a, int b) {
int ans = 1;
while(b > 0) {
if(b & 1)
ans = (1LL * ans * a) % MOD;
b >>= 1;
a = (1LL * a * a) % MOD;
}
return ans;
}
const int MAXN = (int) 1e5 + 5;
int fact[MAXN + 1], invfact[MAXN + 1];
inline int comb(int n, int k) {
if(n < k) return 0;
return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
fact[0] = invfact[0] = 1;
for(i = 1; i <= n + 1; i++) {
fact[i] = (1LL * fact[i - 1] * i) % MOD;
invfact[i] = lgput(fact[i], MOD - 2);
}
k--;
int ans = 0;
for(i = 0; i <= k; i++) {
int cur = (1LL * comb(n + 1, i) * lgput(k - i + 1, n)) % MOD;
if(i & 1) {
cur *= -1;
}
ans += cur;
if(ans < 0) {
ans += MOD;
}
if(ans >= MOD) {
ans -= MOD;
}
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# | 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... |