QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#542347#8339. Rooted TreecrazymoonTL 1498ms56248kbC++201.2kb2024-09-01 00:38:402024-09-01 00:38:40

Judging History

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

  • [2024-09-01 00:38:40]
  • 评测
  • 测评结果:TL
  • 用时:1498ms
  • 内存:56248kb
  • [2024-09-01 00:38:40]
  • 提交

answer

#include <bits/stdc++.h>
#define maxn 10000100
#define int long long
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 9;
int f[maxn];  //叶子节点的期望深度和

int qmi(int a, int b, int m) {
    int res = 1;  a %= m;
    while(b) {
        if(b & 1)  res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve() {
    int m, k, res = 0;
    cin >> m >> k;
    for (int i = 1; i <= k; ++i) {
        // sum * (m - 1) * (i - 1) + (sum + (m - 1) * (i - 1) + 1) * m
        f[i] = (f[i - 1] * (m - 1) % mod * (i - 1) % mod + (f[i - 1] + (m - 1) * (i - 1) + 1) % mod * m % mod) % mod;
        f[i] = f[i] * qmi((m - 1) * (i - 1) + 1, mod - 2, mod) % mod;

        // f[i] = ((m - 1) * (i - 1) % mod * f[i - 1] % mod + (f[i - 1] + 1) * m % mod) % mod;
        // f[i] = f[i] * qmi(1 + i * (m - 1), mod - 2, mod) % mod;
        res = (res + (f[i - 1] * qmi((m - 1) * (i - 1) + 1, mod - 2, mod) % mod + 1) * m % mod) % mod;
    }
    cout << res << '\n';
}

signed 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: 3556kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 134ms
memory: 9224kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1498ms
memory: 56248kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

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

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: -100
Time Limit Exceeded

input:

28 7304152

output:


result: