QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546945 | #8339. Rooted Tree | ucup-team1769 | TL | 168ms | 5408kb | C++20 | 900b | 2024-09-04 16:07:32 | 2024-09-04 16:07:32 |
Judging History
answer
#include <bits/stdc++.h>
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
constexpr int P = 1000000009;
int power(int a, int b) {
int res = 1;
for (; b; b /= 2, a = 1LL * a * a % P) {
if (b % 2) {
res = 1ll * res * a % P;
}
}
return res;
}
int inv(int a, int b) {
return 1ll * a * power(b, P - 2) % P;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int m, k;
std::cin >> m >> k;
std::vector<int> a(k, 0);
for (int i = 1; i < k; i++) {
int res = 1ll * inv((m - 1) * i + 1, (m - 1) * (i - 1) + 1) * a[i - 1] % P;
a[i] = (res + m) % P;
}
for (int i = 0; i < k; i++) {
a[i] = (inv(a[i], (m - 1) * i + 1) + 1) % P;
}
int ans = std::accumulate(a.begin(), a.end(), 0ll) % P;
ans = 1ll * ans * m % P;
std::cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 168ms
memory: 5408kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156