Submission #305542

#TimeUsernameProblemLanguageResultExecution timeMemory
305542quocnguyen1012Asceticism (JOI18_asceticism)C++14
100 / 100
21 ms1152 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define ar array using namespace std; typedef long long ll; typedef pair<int, int> ii; const int mod = 1e9 + 7, maxn = 1e5 + 5; int fact[maxn], ifact[maxn]; int N, K; int power(int a, int b) { if (b == 0) return 1; int res = power(a, b / 2); if (b & 1) return (ll)res * res % mod * a % mod; return (ll)res * res % mod; } int inv(int a) { return power(a, mod - 2); } int binom(int k, int n) { if (k < 0 || n < 0 || k > n) return 0; return (ll)fact[n] * ifact[k] % mod * ifact[n - k] % mod; } void add(int & x, int y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); #endif // LOCAL fact[0] = 1; for (int i = 1; i < maxn; ++i) { fact[i] = (ll)fact[i - 1] * i % mod; } ifact[maxn - 1] = inv(fact[maxn - 1]); for (int i = maxn - 2; i >= 0; --i) { ifact[i] = (ll)ifact[i + 1] * (i + 1) % mod; } cin >> N >> K; int res = 0; for (int i = 0; i <= K; ++i) { int sign = 1; if (i & 1) sign = -1; int way = (ll)power(K - i, N) * binom(i, N + 1) % mod; ///cerr << way << '\n'; add(res, sign * way); } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...