QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396357#8339. Rooted TreeiwewTL 139ms3704kbC++20708b2024-04-22 17:50:312024-04-22 17:50:33

Judging History

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

  • [2024-04-22 17:50:33]
  • 评测
  • 测评结果:TL
  • 用时:139ms
  • 内存:3704kb
  • [2024-04-22 17:50:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1e9 + 9;

ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

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

	ll M, K;
	cin >> M >> K;

	ll last = 0, cur = 0, ans = 0;
	for(int i = 1; i <= K; i ++ ) {
		cur = (1ll * i * (M - 1) + 1) % mod * qpow((1ll * (i - 1) * (M - 1) + 1) % mod, mod - 2) % mod * last % mod;
		cur = (cur + M) % mod;

		ans = (ans + (last * qpow((1ll * (i - 1) * (M - 1) + 1) % mod, mod - 2) % mod + 1) % mod) % mod;
		last = cur;
	}

	cout << ans * M % mod << '\n';

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 139ms
memory: 3656kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:

198541581

result: