QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639495 | #8339. Rooted Tree | Blamek# | TL | 1390ms | 3720kb | C++17 | 853b | 2024-10-13 20:00:13 | 2024-10-13 20:00:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 9;
int qmi(int a, int b = mod - 2) {
int ans = 1;
if (b == 0) return ans;
if (b & 1) ans = a;
return ans * qmi(a * a % mod, b >> 1) % mod;
}
void solve() {
int m, k;
cin >> m >> k;
int ans = 0, res = 0, sum = 1;
for (int i = 1; i <= k; i++) {
int z = (res * qmi(sum) % mod + 1);
if (z == mod) z = 0;
ans = (ans + z * m) % mod;
sum = sum + m - 1;
if (res < z - 1) res += mod;
res -= z - 1;
res += z * m;
res%=mod;
// cout<<ans<<" "<<res<<" "<<sum<<"\n";
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 128ms
memory: 3652kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1390ms
memory: 3592kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: -100
Time Limit Exceeded
input:
28 7304152
output:
457266679