QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548328#8339. Rooted Treearies_yff#TL 136ms8148kbC++20959b2024-09-05 17:12:302024-09-05 17:12:31

Judging History

你现在查看的是最新测评结果

  • [2024-09-05 17:12:31]
  • 评测
  • 测评结果:TL
  • 用时:136ms
  • 内存:8148kb
  • [2024-09-05 17:12:30]
  • 提交

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

result: