QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#714269 | #8339. Rooted Tree | lolte | WA | 134ms | 10032kb | C++20 | 781b | 2024-11-05 22:19:37 | 2024-11-05 22:19:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int m,k;
const int mod = 1e9+9 , maxn = 1e7+10;
int gcd(int x,int y) {
if (!y) return x;
return gcd(y,x%y);
}
int kasumi(int x,int y) {
int ans=1,base=x;
while (y) {
if (y&1) ans=(ans*base)%mod;
base=(base*base)%mod;
y>>=1;
}
return ans;
}
int inv(int x) {
return kasumi(x%mod,mod-2)%mod;
}
int sum[maxn];
signed main(){
ios::sync_with_stdio(false);
//std::cin.tie(nullptr);std::cout.tie(nullptr);
cin>>m>>k;
sum[0]=0;
for (int i=1;i<=k;++i) {
sum[i]=(sum[i-1]*(((m-1)*i+1)%mod)*inv((m-1)*(i-1)+1)+m)%mod;
}
int ans=0;
for (int i=1;i<=k;++i) {
ans=(ans+(sum[i-1]*inv((m-1)*(i-1)+1)+1)*m)%mod;
}
cout<<ans%mod<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: -100
Wrong Answer
time: 134ms
memory: 10032kb
input:
83 613210
output:
-241998874
result:
wrong answer 1st numbers differ - expected: '424200026', found: '-241998874'