QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627936#8339. Rooted Treexmseer#TL 147ms3684kbC++201011b2024-10-10 17:43:352024-10-10 17:43:46

Judging History

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

  • [2024-10-10 17:43:46]
  • 评测
  • 测评结果:TL
  • 用时:147ms
  • 内存:3684kb
  • [2024-10-10 17:43:35]
  • 提交

answer

#include <iostream>

using namespace std;


long long power(long long base, int exp, int mod) {
    if (base == 0) {
        return 0;
    }
    if (exp == 1) {
        return base;
    }
    if ((exp & 1) == 1) {
        return (power((base * base) % mod, (exp >> 1), mod) * base) % mod;
    } else {
        return power((base * base) % mod, (exp >> 1), mod);
    }
}
long long modInverse(long long a, int mod) {
    long long power(long long base, int exp, int mod);
    return power(a, mod - 2, mod);
}


int main() {
    int n, k;
    cin >> n >> k;
    int mod = 1e9 + 9;
    long long ans = 0;
    long long v = 0;
    long long sum = 1;

    for (int i = 1; i <= k; i++) {
        ans += (v + 1) * n;
        ans %= mod;
        v = ((v + 1) * n + (sum - 1) * v) % mod * modInverse((sum + n - 1) % mod, mod);
        v %= mod;
        sum = sum - 1 + n;
        sum %= mod;
        // cout << ans << endl;
    }
    
    cout << ans << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 147ms
memory: 3684kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:

198541581

result: