QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686718 | #8339. Rooted Tree | ucup-team1412 | TL | 135ms | 7056kb | C++14 | 685b | 2024-10-29 15:18:23 | 2024-10-29 15:18:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P=1000000009;
int a[10000005];
ll quickpow(ll x, ll y) {
ll ans = 1;
while (y) {
if (y & 1) ans *= x;
ans %= P;
y >>= 1;
x *= x;
x %= P;
}
return ans % P;
}
int main() {
ll m,k;
cin>>m>>k;
a[0]=0;
ll ans=1;
for(int i=1;i<k;i++){
ll x1=quickpow(((m-1)*(i-1)+1),P-2);
ll x2=quickpow(((m-1)*i+1),P-2);
a[i]=((((a[i-1]*((m-1)*i+1))%P)*x1)%P+m)%P;
ans=(ans+1+(a[i]*x2)%P)%P;
}
ans=ans*m%P;
cout<<ans;
return 0;
}
/*
2
6
2 1 2 2 1 1
4
1 2 1 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 135ms
memory: 7056kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156
output:
198541581