QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639077#8339. Rooted TreeYinyuDreamTL 1368ms145948kbC++20707b2024-10-13 17:50:492024-10-13 17:50:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 17:50:50]
  • 评测
  • 测评结果:TL
  • 用时:1368ms
  • 内存:145948kb
  • [2024-10-13 17:50:49]
  • 提交

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

output:


result: