QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#396357 | #8339. Rooted Tree | iwew | TL | 139ms | 3704kb | C++20 | 708b | 2024-04-22 17:50:31 | 2024-04-22 17:50:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 9;
ll qpow(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll M, K;
cin >> M >> K;
ll last = 0, cur = 0, ans = 0;
for(int i = 1; i <= K; i ++ ) {
cur = (1ll * i * (M - 1) + 1) % mod * qpow((1ll * (i - 1) * (M - 1) + 1) % mod, mod - 2) % mod * last % mod;
cur = (cur + M) % mod;
ans = (ans + (last * qpow((1ll * (i - 1) * (M - 1) + 1) % mod, mod - 2) % mod + 1) % mod) % mod;
last = cur;
}
cout << ans * M % mod << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 139ms
memory: 3656kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156
output:
198541581