QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661021#8339. Rooted TreeKomorebie#TL 1473ms112492kbC++17659b2024-10-20 14:21:062024-10-20 14:21:07

Judging History

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

  • [2024-10-20 14:21:07]
  • 评测
  • 测评结果:TL
  • 用时:1473ms
  • 内存:112492kb
  • [2024-10-20 14:21:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 1e7+10;
const ll mod=1e9+9;

ll m,k;
ll f[N],g[N],s[N],h[N];

ll qmi(ll k,ll p,ll m){
    ll res=1,a=k;
    while(p){
        if(p&1) res=res*a%m;
        a=a*a%m;
        p=p>>1;
    }
    return res;
}

int main(){
    cin>>m>>k;
    s[0]=1;
    for(int i=1;i<=k;i++) s[i]=(1+i*(m-1))%mod;
    for(int i=1;i<=k;i++){
        g[i]=(g[i-1]+(m*(s[i-1]+g[i-1]+i-1+mod)%mod-g[i-1]+mod)%mod*qmi(s[i-1],mod-2,mod)%mod)%mod;
        g[i+1]=(g[i]+(m*(s[i]+g[i-1])%mod-g[i]+mod)%mod*qmi(s[i],mod-2,mod)%mod)%mod;
    }
    cout<<g[k]<<endl;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 5772kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5724kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 137ms
memory: 16412kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1473ms
memory: 112492kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5720kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: -100
Time Limit Exceeded

input:

28 7304152

output:

457266679

result: