QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661021 | #8339. Rooted Tree | Komorebie# | TL | 1473ms | 112492kb | C++17 | 659b | 2024-10-20 14:21:06 | 2024-10-20 14:21:07 |
Judging History
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