QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639077 | #8339. Rooted Tree | YinyuDream | TL | 1368ms | 145948kb | C++20 | 707b | 2024-10-13 17:50:49 | 2024-10-13 17:50:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p=1e9+9;
int ksm(int a,int b){
if(b==0){
return 1;
}
int ans=ksm(a,b/2);
ans=1ll*ans*ans%p;
if(b&1){
ans=1ll*ans*a%p;
}
return ans;
}
int inv(int x){
return ksm(x,p-2);
}
int main(){
ll m,k;
cin>>m>>k;
vector<int> 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;
f[i]=f[i]*inv(val[i])%p;
g[i]=(g[i-1]+m*f[i-1])%p;
}
cout<<g[k]<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 118ms
memory: 15120kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1262ms
memory: 134388kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 1368ms
memory: 145948kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 770ms
memory: 83468kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: -100
Time Limit Exceeded
input:
51 9921154