이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://en.wikipedia.org/wiki/Eulerian_number not very nice tbh :()
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5, MD = 1e9 + 7;
int bpow(int a, int b = MD - 2) {
int res = 1;
for (; b; a = (long long) a * a % MD, b /= 2) {
if (b & 1) {
res = (long long) res * a % MD;
}
}
return res;
}
int n, k;
int fact[N], ifact[N];
int C(int k, int n) {
return (long long) fact[n] * ifact[k] % MD * ifact[n - k] % MD;
}
void add(int &x, int y) {
if ((x += y) >= MD) {
x -= MD;
}
if (x < 0) {
x += MD;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k; --k;
fact[0] = 1;
for (int i = 1; i <= n + 1; ++i) {
fact[i] = (long long) fact[i - 1] * i % MD;
}
ifact[n + 1] = bpow(fact[n + 1]);
for (int i = n; i >= 0; --i) {
ifact[i] = (long long) ifact[i + 1] * (i + 1) % MD;
}
int res = 0;
for (int i = 0; i <= k; ++i) {
add(res, (long long) (i & 1 ? -1 : 1) * C(i, n + 1) * bpow(k + 1 - i, n) % MD);
}
cout << res;
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... |