Submission #1129703

#TimeUsernameProblemLanguageResultExecution timeMemory
1129703antonnAsceticism (JOI18_asceticism)C++20
100 / 100
10 ms1352 KiB
// https://oeis.org/A008292 #include <bits/stdc++.h> using namespace std; const int Nmax = (1 << 17); const int Mod = 1e9 + 7; int Fact[Nmax], IFact[Nmax]; int mul(int a, int b) { return 1LL * a * b % Mod; } int pow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int binom(int n, int k) { if (n < k) return 0; return mul(Fact[n], mul(IFact[k], IFact[n - k])); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); Fact[0] = 1; for (int i = 1; i < Nmax; i++) Fact[i] = mul(Fact[i - 1], i); IFact[Nmax - 1] = pow(Fact[Nmax - 1], Mod - 2); for (int i = Nmax - 2; i >= 0; i--) IFact[i] = mul(IFact[i + 1], i + 1); int N, K; cin >> N >> K; int answer = 0; for (int i = 0; i <= K; i++) { int coef = mul(pow(K - i, N), binom(N + 1, i)) % Mod; if (i % 2 == 0) { answer += coef; if (answer >= Mod) answer -= Mod; } if (i % 2 == 1) { answer -= coef; if (answer < 0) answer += Mod; } } cout << answer << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...