QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706471 | #8339. Rooted Tree | Anneliese# | TL | 141ms | 16740kb | C++14 | 1009b | 2024-11-03 11:34:14 | 2024-11-03 11:34:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ll = long long;
const int N = 10000005;
#define rep(i,a ,b ) for(int i = a ;i<=b;i++)
#define pre(i,a ,b ) for(int i = a ;i>=b;i--)
#define pb push_back
#define sc(x) scanf("%d",&x)
ll dp[N];
ll f[N];
ll dp2[N];
const int mod=1e9+9;
ll ksm(ll a,ll b){ll res=1;
while(b){
if(b%2==1)res=res*a%mod;a=a*a%mod;b/=2;
}
return res;
}
void solve() {
int m,k;
sc(m);sc(k);
f[0]=1;
rep(i,1,k)f[i]=(f[i-1]+m-1)%mod;
ll res=0;
rep(i,1,k){
dp[i]=dp[i-1]+(dp[i-1]*(m-1)%mod+f[i-1]*m%mod)*ksm(f[i-1],mod-2)%mod;//dp[i]为叶子节点深度之和
dp[i]%=mod;
res=(res+(dp[i-1]*m%mod+f[i-1]*m%mod)*ksm(f[i-1],mod-2)%mod)%mod;
// cout<<dp[i-1]*m%mod+f[i-1]*m%mod*ksm(f[i-1],mod-2)%mod<<" "<<endl;
}
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t ;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5868kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 141ms
memory: 16740kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156
output:
198541581