QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639057 | #8339. Rooted Tree | YinyuDream | TL | 1342ms | 174312kb | C++20 | 696b | 2024-10-13 17:47:17 | 2024-10-13 17:47:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p=1e9+9;
ll ksm(ll a,ll b){
if(b==0){
return 1;
}
ll ans=ksm(a,b/2);
ans=ans*ans%p;
if(b&1){
ans=ans*a%p;
}
return ans;
}
ll inv(ll x){
return ksm(x,p-2);
}
int main(){
ll m,k;
cin>>m>>k;
vector<ll> val(k+1);
val[0]=1;
for(int i=1;i<=k;i++){
val[i]=(val[i-1]+m-1)%p;
}
vector<ll> f(k+1),g(k+1);
f[0]=1;
for(int i=1;i<=k;i++){
f[i]=(f[i-1]*(val[i-1]-1)%p+m*(f[i-1]+1)%p)%p;
f[i]=f[i]*inv(val[i])%p;
g[i]=(g[i-1]+m*f[i-1]%p)%p;
}
cout<<g[k]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3500kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 112ms
memory: 17608kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1232ms
memory: 160532kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 1342ms
memory: 174312kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 747ms
memory: 99376kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: -100
Time Limit Exceeded
input:
51 9921154