QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638799 | #8339. Rooted Tree | ainuo | WA | 71ms | 16932kb | C++14 | 757b | 2024-10-13 16:57:32 | 2024-10-13 16:57:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+10;
const int mod=1e9+9;
ll num[N],dp[N];
ll qpow(ll n,ll m)
{
ll ans=1;
while(m)
{
if(m&1) ans=ans*n%mod;
m>>=1;
n=n*n%mod;
}
return ans;
}
ll getInv(ll a)
{
return qpow(a,mod-2);
}
int main()
{
int m,k;
ll ans=0;
cin>>m>>k;
num[0]=1;
for(int i=1;i<=k;i++) num[i]=num[i-1]+m-1;
dp[0]=0;
for(int i=1;i<=k;i++)
{
dp[i]=((((dp[i-1]*num[i-1])%mod+((dp[i-1]+1)*m)%mod-dp[i-1])%mod)*getInv(num[i]))%mod;
ans=(ans+dp[i-1])%mod;
}
// cout<<num[1]<<'\n';
// cout<<(dp[1]*num[1])%mod<<'\n';
ans=(ans+((dp[k]*num[k])%mod))%mod;
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5760kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5608kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: -100
Wrong Answer
time: 71ms
memory: 16932kb
input:
83 613210
output:
-575799983
result:
wrong answer 1st numbers differ - expected: '424200026', found: '-575799983'