///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int fact[N], inv[N];
inline int Pow(int a, int p) {
int ret = 1; while(p) {
if(p & 1) ret = (ll) ret * a % mod;
a = (ll) a * a % mod;
p >>= 1;
} return ret;
}
int C(int n, int r) {
int ret = (ll) fact[n] * inv[r] % mod;
return (ll) ret * inv[n - r] % mod;
}
void add(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }
void sub(int &a, int b) { a = a - b < 0 ? a - b + mod : a - b; }
int mul(int a, int b) { return (ll) a * b % mod; }
int main() {
fact[0] = 1;
for(int i = 1; i < N; i++)
fact[i] = mul(fact[i - 1], i);
inv[N - 1] = Pow(fact[N - 1], mod - 2);
for(int i = N - 2; i >= 0; i--)
inv[i] = mul(inv[i + 1], i + 1);
int n, k; scanf("%d %d", &n, &k);
int ans = 0;
for(int i = 0; i <= k; i++) {
int x = Pow(k - i, n);
if(i <= k - 1) sub(x, Pow(k - i - 1, n));
x = mul(x, C(n, i));
if(i & 1) sub(ans, x);
else add(ans, x);
}
printf("%d\n", ans);
}
Compilation message
asceticism.cpp: In function 'int main()':
asceticism.cpp:38:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n, k; scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1312 KB |
Output is correct |
5 |
Correct |
4 ms |
1312 KB |
Output is correct |
6 |
Correct |
4 ms |
1312 KB |
Output is correct |
7 |
Correct |
4 ms |
1312 KB |
Output is correct |
8 |
Correct |
4 ms |
1312 KB |
Output is correct |
9 |
Correct |
4 ms |
1336 KB |
Output is correct |
10 |
Correct |
4 ms |
1336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1312 KB |
Output is correct |
5 |
Correct |
4 ms |
1312 KB |
Output is correct |
6 |
Correct |
4 ms |
1312 KB |
Output is correct |
7 |
Correct |
4 ms |
1312 KB |
Output is correct |
8 |
Correct |
4 ms |
1312 KB |
Output is correct |
9 |
Correct |
4 ms |
1336 KB |
Output is correct |
10 |
Correct |
4 ms |
1336 KB |
Output is correct |
11 |
Correct |
4 ms |
1336 KB |
Output is correct |
12 |
Correct |
4 ms |
1336 KB |
Output is correct |
13 |
Correct |
4 ms |
1336 KB |
Output is correct |
14 |
Correct |
4 ms |
1336 KB |
Output is correct |
15 |
Correct |
4 ms |
1336 KB |
Output is correct |
16 |
Correct |
4 ms |
1464 KB |
Output is correct |
17 |
Correct |
4 ms |
1464 KB |
Output is correct |
18 |
Correct |
4 ms |
1464 KB |
Output is correct |
19 |
Correct |
4 ms |
1524 KB |
Output is correct |
20 |
Correct |
4 ms |
1524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1312 KB |
Output is correct |
5 |
Correct |
4 ms |
1312 KB |
Output is correct |
6 |
Correct |
4 ms |
1312 KB |
Output is correct |
7 |
Correct |
4 ms |
1312 KB |
Output is correct |
8 |
Correct |
4 ms |
1312 KB |
Output is correct |
9 |
Correct |
4 ms |
1336 KB |
Output is correct |
10 |
Correct |
4 ms |
1336 KB |
Output is correct |
11 |
Correct |
4 ms |
1336 KB |
Output is correct |
12 |
Correct |
4 ms |
1336 KB |
Output is correct |
13 |
Correct |
4 ms |
1336 KB |
Output is correct |
14 |
Correct |
4 ms |
1336 KB |
Output is correct |
15 |
Correct |
4 ms |
1336 KB |
Output is correct |
16 |
Correct |
4 ms |
1464 KB |
Output is correct |
17 |
Correct |
4 ms |
1464 KB |
Output is correct |
18 |
Correct |
4 ms |
1464 KB |
Output is correct |
19 |
Correct |
4 ms |
1524 KB |
Output is correct |
20 |
Correct |
4 ms |
1524 KB |
Output is correct |
21 |
Correct |
4 ms |
1524 KB |
Output is correct |
22 |
Correct |
4 ms |
1524 KB |
Output is correct |
23 |
Correct |
4 ms |
1524 KB |
Output is correct |
24 |
Correct |
5 ms |
1524 KB |
Output is correct |
25 |
Correct |
4 ms |
1524 KB |
Output is correct |
26 |
Correct |
4 ms |
1524 KB |
Output is correct |
27 |
Correct |
4 ms |
1524 KB |
Output is correct |
28 |
Correct |
4 ms |
1524 KB |
Output is correct |
29 |
Correct |
4 ms |
1524 KB |
Output is correct |
30 |
Correct |
4 ms |
1524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1312 KB |
Output is correct |
5 |
Correct |
4 ms |
1312 KB |
Output is correct |
6 |
Correct |
4 ms |
1312 KB |
Output is correct |
7 |
Correct |
4 ms |
1312 KB |
Output is correct |
8 |
Correct |
4 ms |
1312 KB |
Output is correct |
9 |
Correct |
4 ms |
1336 KB |
Output is correct |
10 |
Correct |
4 ms |
1336 KB |
Output is correct |
11 |
Correct |
4 ms |
1336 KB |
Output is correct |
12 |
Correct |
4 ms |
1336 KB |
Output is correct |
13 |
Correct |
4 ms |
1336 KB |
Output is correct |
14 |
Correct |
4 ms |
1336 KB |
Output is correct |
15 |
Correct |
4 ms |
1336 KB |
Output is correct |
16 |
Correct |
4 ms |
1464 KB |
Output is correct |
17 |
Correct |
4 ms |
1464 KB |
Output is correct |
18 |
Correct |
4 ms |
1464 KB |
Output is correct |
19 |
Correct |
4 ms |
1524 KB |
Output is correct |
20 |
Correct |
4 ms |
1524 KB |
Output is correct |
21 |
Correct |
4 ms |
1524 KB |
Output is correct |
22 |
Correct |
4 ms |
1524 KB |
Output is correct |
23 |
Correct |
4 ms |
1524 KB |
Output is correct |
24 |
Correct |
5 ms |
1524 KB |
Output is correct |
25 |
Correct |
4 ms |
1524 KB |
Output is correct |
26 |
Correct |
4 ms |
1524 KB |
Output is correct |
27 |
Correct |
4 ms |
1524 KB |
Output is correct |
28 |
Correct |
4 ms |
1524 KB |
Output is correct |
29 |
Correct |
4 ms |
1524 KB |
Output is correct |
30 |
Correct |
4 ms |
1524 KB |
Output is correct |
31 |
Correct |
4 ms |
1524 KB |
Output is correct |
32 |
Correct |
4 ms |
1524 KB |
Output is correct |
33 |
Correct |
5 ms |
1524 KB |
Output is correct |
34 |
Correct |
7 ms |
1524 KB |
Output is correct |
35 |
Correct |
20 ms |
1524 KB |
Output is correct |
36 |
Correct |
22 ms |
1524 KB |
Output is correct |
37 |
Correct |
24 ms |
1524 KB |
Output is correct |
38 |
Correct |
6 ms |
1524 KB |
Output is correct |
39 |
Correct |
10 ms |
1524 KB |
Output is correct |
40 |
Correct |
12 ms |
1524 KB |
Output is correct |