QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548328 | #8339. Rooted Tree | aries_yff# | TL | 136ms | 8148kb | C++20 | 959b | 2024-09-05 17:12:30 | 2024-09-05 17:12:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 9;
//a^k的快速幂
ll quick_power(ll a,ll k)
{
ll res = 1;
while(k){
if(k&1)res = (res*a)%mod;
a = (a%mod*a)%mod;
k>>=1;
}
return res;
}
//a在模mod下的逆元,利用费马小定理求解,要求mod为素数
ll inv(ll a)
{
return quick_power(a,mod - 2);
}
void solve()
{
ll m,k;
cin>>m>>k;
vector<ll>f(k+10,0);
ll d = 0;
ll ans = 0;
for(int i=1;i<=k;i++){
ans = (ans + d) % mod;
f[i] = (f[i-1] - d + m*(d+1)) % mod;
d = (d + m*inv(i*m-(i-1))%mod) % mod;
// cerr<<"d = "<<d<<"\n";
// cerr<<f[i]<<"\n";
}
cout<<((ans + f[k])%mod + mod)%mod;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 136ms
memory: 8148kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156
output:
198541581