QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546945#8339. Rooted Treeucup-team1769TL 168ms5408kbC++20900b2024-09-04 16:07:322024-09-04 16:07:32

Judging History

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

  • [2024-09-04 16:07:32]
  • 评测
  • 测评结果:TL
  • 用时:168ms
  • 内存:5408kb
  • [2024-09-04 16:07:32]
  • 提交

answer

#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

constexpr int P = 1000000009;

int power(int a, int b) {
    int res = 1;
    for (; b; b /= 2, a = 1LL * a * a % P) {
        if (b % 2) {
            res = 1ll * res * a % P;
        }
    }
    return res;
}

int inv(int a, int b) {
	return 1ll * a * power(b, P - 2) % P;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int m, k;
	std::cin >> m >> k;
	
	std::vector<int> a(k, 0);
	for (int i = 1; i < k; i++) {
		int res = 1ll * inv((m - 1) * i + 1, (m - 1) * (i - 1) + 1) * a[i - 1] % P;
		a[i] = (res + m) % P;
	}
	for (int i = 0; i < k; i++) {
		a[i] = (inv(a[i], (m - 1) * i + 1) + 1) % P;
	}
	int ans = std::accumulate(a.begin(), a.end(), 0ll) % P;
	ans = 1ll * ans * m % P;

	std::cout << ans << "\n";

	return 0;
}

詳細信息

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 168ms
memory: 5408kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:


result: