#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
const int N = 1e5 + 7, MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) { return (n % MOD + MOD) % MOD; }
int fp(int a, int p) {
int ans = 1, cur = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = (ans * cur) % MOD;
cur = (cur * cur) % MOD;
}
return ans;
}
int inv(int x) { return fp(x, MOD - 2); }
int dv(int a, int b) { return (a * inv(b)) % MOD; }
int f[N];
int C(int n, int k) { return dv(f[n], (f[n - k] * f[k]) % MOD); }
int eulerian(int n, int m) {
int ans = 0;
for (int k = 0; k <= m; ++k) {
if (k & 1) ans -= C(n + 1, k) * fp(m + 1 - k, n);
else ans += C(n + 1, k) * fp(m + 1 - k, n);
}
return mod(ans);
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
f[0] = 1;
for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * i) % MOD;
int n, k;
cin >> n >> k;
cout << eulerian(n, k - 1) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1148 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1148 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
3 ms |
1204 KB |
Output is correct |
14 |
Correct |
3 ms |
1116 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1148 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
3 ms |
1204 KB |
Output is correct |
14 |
Correct |
3 ms |
1116 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1144 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1148 KB |
Output is correct |
25 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1148 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
3 ms |
1204 KB |
Output is correct |
14 |
Correct |
3 ms |
1116 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1144 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1148 KB |
Output is correct |
25 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |