QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#542347 | #8339. Rooted Tree | crazymoon | TL | 1498ms | 56248kb | C++20 | 1.2kb | 2024-09-01 00:38:40 | 2024-09-01 00:38:40 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 10000100
#define int long long
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 9;
int f[maxn]; //叶子节点的期望深度和
int qmi(int a, int b, int m) {
int res = 1; a %= m;
while(b) {
if(b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
void solve() {
int m, k, res = 0;
cin >> m >> k;
for (int i = 1; i <= k; ++i) {
// sum * (m - 1) * (i - 1) + (sum + (m - 1) * (i - 1) + 1) * m
f[i] = (f[i - 1] * (m - 1) % mod * (i - 1) % mod + (f[i - 1] + (m - 1) * (i - 1) + 1) % mod * m % mod) % mod;
f[i] = f[i] * qmi((m - 1) * (i - 1) + 1, mod - 2, mod) % mod;
// f[i] = ((m - 1) * (i - 1) % mod * f[i - 1] % mod + (f[i - 1] + 1) * m % mod) % mod;
// f[i] = f[i] * qmi(1 + i * (m - 1), mod - 2, mod) % mod;
res = (res + (f[i - 1] * qmi((m - 1) * (i - 1) + 1, mod - 2, mod) % mod + 1) * m % mod) % mod;
}
cout << res << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 134ms
memory: 9224kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1498ms
memory: 56248kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: -100
Time Limit Exceeded
input:
28 7304152