#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");
#define random rand() ^ (rand() << 5)
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int mod = (int)1e9 + 7;
ll fact[N];
ll mult(ll a, ll b) {
return a * b % mod;
}
ll add(ll a, ll b) {
a += b;
if (a > mod) a -= mod;
return a;
}
ll sub(ll a, ll b) {
a -= b;
while (a < 0) a += mod;
return a;
}
void precalc() {
fact[0] = 1;
for (ll i = 1; i < N; i++) {
fact[i] = mult(fact[i - 1], i);
}
}
ll binpow(ll a, int n) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res = mult(res, a);
}
a = mult(a, a);
n >>= 1;
}
return res;
}
ll cnk(ll n, ll k) {
if (k > n) return 0;
return mult(mult(fact[n], binpow(fact[k], mod - 2)), binpow(fact[n - k], mod - 2));
}
int n, m;
main() {
precalc();
scanf("%d %d", &n, &m);
m--;
ll ans = 0;
for (int k = 0; k <= m + 1; k++) {
if (k & 1) {
ans = sub(ans, mult(cnk(n + 1, k), binpow(m + 1 - k, n)));
} else {
ans = add(ans, mult(cnk(n + 1, k), binpow(m + 1 - k, n)));
}
}
cout << ans;
}
Compilation message
asceticism.cpp:67:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
asceticism.cpp: In function 'int main()':
asceticism.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8056 KB |
Output is correct |
2 |
Correct |
26 ms |
8164 KB |
Output is correct |
3 |
Correct |
26 ms |
8216 KB |
Output is correct |
4 |
Correct |
27 ms |
8420 KB |
Output is correct |
5 |
Correct |
27 ms |
8420 KB |
Output is correct |
6 |
Correct |
26 ms |
8420 KB |
Output is correct |
7 |
Correct |
52 ms |
8548 KB |
Output is correct |
8 |
Correct |
27 ms |
8556 KB |
Output is correct |
9 |
Correct |
27 ms |
8556 KB |
Output is correct |
10 |
Correct |
27 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8056 KB |
Output is correct |
2 |
Correct |
26 ms |
8164 KB |
Output is correct |
3 |
Correct |
26 ms |
8216 KB |
Output is correct |
4 |
Correct |
27 ms |
8420 KB |
Output is correct |
5 |
Correct |
27 ms |
8420 KB |
Output is correct |
6 |
Correct |
26 ms |
8420 KB |
Output is correct |
7 |
Correct |
52 ms |
8548 KB |
Output is correct |
8 |
Correct |
27 ms |
8556 KB |
Output is correct |
9 |
Correct |
27 ms |
8556 KB |
Output is correct |
10 |
Correct |
27 ms |
8556 KB |
Output is correct |
11 |
Correct |
27 ms |
8556 KB |
Output is correct |
12 |
Correct |
27 ms |
8556 KB |
Output is correct |
13 |
Correct |
27 ms |
8556 KB |
Output is correct |
14 |
Correct |
27 ms |
8556 KB |
Output is correct |
15 |
Correct |
28 ms |
8556 KB |
Output is correct |
16 |
Correct |
28 ms |
8556 KB |
Output is correct |
17 |
Correct |
27 ms |
8556 KB |
Output is correct |
18 |
Correct |
27 ms |
8556 KB |
Output is correct |
19 |
Correct |
29 ms |
8556 KB |
Output is correct |
20 |
Correct |
27 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8056 KB |
Output is correct |
2 |
Correct |
26 ms |
8164 KB |
Output is correct |
3 |
Correct |
26 ms |
8216 KB |
Output is correct |
4 |
Correct |
27 ms |
8420 KB |
Output is correct |
5 |
Correct |
27 ms |
8420 KB |
Output is correct |
6 |
Correct |
26 ms |
8420 KB |
Output is correct |
7 |
Correct |
52 ms |
8548 KB |
Output is correct |
8 |
Correct |
27 ms |
8556 KB |
Output is correct |
9 |
Correct |
27 ms |
8556 KB |
Output is correct |
10 |
Correct |
27 ms |
8556 KB |
Output is correct |
11 |
Correct |
27 ms |
8556 KB |
Output is correct |
12 |
Correct |
27 ms |
8556 KB |
Output is correct |
13 |
Correct |
27 ms |
8556 KB |
Output is correct |
14 |
Correct |
27 ms |
8556 KB |
Output is correct |
15 |
Correct |
28 ms |
8556 KB |
Output is correct |
16 |
Correct |
28 ms |
8556 KB |
Output is correct |
17 |
Correct |
27 ms |
8556 KB |
Output is correct |
18 |
Correct |
27 ms |
8556 KB |
Output is correct |
19 |
Correct |
29 ms |
8556 KB |
Output is correct |
20 |
Correct |
27 ms |
8556 KB |
Output is correct |
21 |
Correct |
27 ms |
8556 KB |
Output is correct |
22 |
Correct |
27 ms |
8556 KB |
Output is correct |
23 |
Correct |
28 ms |
8556 KB |
Output is correct |
24 |
Correct |
29 ms |
8556 KB |
Output is correct |
25 |
Correct |
28 ms |
8560 KB |
Output is correct |
26 |
Correct |
29 ms |
8692 KB |
Output is correct |
27 |
Correct |
29 ms |
8692 KB |
Output is correct |
28 |
Correct |
29 ms |
8692 KB |
Output is correct |
29 |
Correct |
27 ms |
8692 KB |
Output is correct |
30 |
Correct |
30 ms |
8692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8056 KB |
Output is correct |
2 |
Correct |
26 ms |
8164 KB |
Output is correct |
3 |
Correct |
26 ms |
8216 KB |
Output is correct |
4 |
Correct |
27 ms |
8420 KB |
Output is correct |
5 |
Correct |
27 ms |
8420 KB |
Output is correct |
6 |
Correct |
26 ms |
8420 KB |
Output is correct |
7 |
Correct |
52 ms |
8548 KB |
Output is correct |
8 |
Correct |
27 ms |
8556 KB |
Output is correct |
9 |
Correct |
27 ms |
8556 KB |
Output is correct |
10 |
Correct |
27 ms |
8556 KB |
Output is correct |
11 |
Correct |
27 ms |
8556 KB |
Output is correct |
12 |
Correct |
27 ms |
8556 KB |
Output is correct |
13 |
Correct |
27 ms |
8556 KB |
Output is correct |
14 |
Correct |
27 ms |
8556 KB |
Output is correct |
15 |
Correct |
28 ms |
8556 KB |
Output is correct |
16 |
Correct |
28 ms |
8556 KB |
Output is correct |
17 |
Correct |
27 ms |
8556 KB |
Output is correct |
18 |
Correct |
27 ms |
8556 KB |
Output is correct |
19 |
Correct |
29 ms |
8556 KB |
Output is correct |
20 |
Correct |
27 ms |
8556 KB |
Output is correct |
21 |
Correct |
27 ms |
8556 KB |
Output is correct |
22 |
Correct |
27 ms |
8556 KB |
Output is correct |
23 |
Correct |
28 ms |
8556 KB |
Output is correct |
24 |
Correct |
29 ms |
8556 KB |
Output is correct |
25 |
Correct |
28 ms |
8560 KB |
Output is correct |
26 |
Correct |
29 ms |
8692 KB |
Output is correct |
27 |
Correct |
29 ms |
8692 KB |
Output is correct |
28 |
Correct |
29 ms |
8692 KB |
Output is correct |
29 |
Correct |
27 ms |
8692 KB |
Output is correct |
30 |
Correct |
30 ms |
8692 KB |
Output is correct |
31 |
Correct |
26 ms |
8692 KB |
Output is correct |
32 |
Correct |
31 ms |
8692 KB |
Output is correct |
33 |
Correct |
36 ms |
8692 KB |
Output is correct |
34 |
Correct |
56 ms |
8692 KB |
Output is correct |
35 |
Correct |
182 ms |
8692 KB |
Output is correct |
36 |
Correct |
204 ms |
8764 KB |
Output is correct |
37 |
Correct |
218 ms |
8764 KB |
Output is correct |
38 |
Correct |
51 ms |
8764 KB |
Output is correct |
39 |
Correct |
88 ms |
8764 KB |
Output is correct |
40 |
Correct |
102 ms |
8764 KB |
Output is correct |