QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686720#8339. Rooted Treeucup-team1412TL 138ms6700kbC++14651b2024-10-29 15:19:162024-10-29 15:19:17

Judging History

This is the latest submission verdict.

  • [2024-10-29 15:19:17]
  • Judged
  • Verdict: TL
  • Time: 138ms
  • Memory: 6700kb
  • [2024-10-29 15:19:16]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int P=1000000009;

int a[10000005]; 

ll quickpow(ll x, ll y) {
    ll ans = 1;
    while (y) {
        if (y & 1) ans *= x;
        ans %= P;
        y >>= 1;
        x *= x;
        x %= P;
    }
    return ans % P;
}

int main() {
    ll m,k;
    cin>>m>>k;

    a[0]=0;
    ll ans=1;
    for(int i=1;i<k;i++){
        ll x1=quickpow(((m-1)*(i-1)+1),P-2);
        ll x2=quickpow(((m-1)*i+1),P-2);
        a[i]=((((a[i-1]*((m-1)*i+1))%P)*x1)%P+m)%P;
        ans=(ans+1+(a[i]*x2)%P)%P;
    }
    ans=ans*m%P;
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3680kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 138ms
memory: 6700kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:

198541581

result: