QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713224#8339. Rooted Treeshunhualin#TL 1436ms3668kbC++20795b2024-11-05 18:40:512024-11-05 18:40:51

Judging History

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

  • [2024-11-05 18:40:51]
  • 评测
  • 测评结果:TL
  • 用时:1436ms
  • 内存:3668kb
  • [2024-11-05 18:40:51]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
const int mod = 1e9 + 9;
const int N = 1e5 + 50;
using namespace std;
int quickpow(int n, int m){
	int res = 1;
	while(m){
		if(m & 1){
			res = res * n % mod;
		}
		n = n * n % mod;
		m = m >> 1;
	}
	return res;
} 
void slove(){
	int m, k; cin >> m >> k;
	int s1 = m, s2 = m, s3 = m;
	for(int i = 2; i <= k; i++){
		int ss1 = s1 + m - 1;
		int ss2 = s2 + (m - 1) * s2 % mod * quickpow(s1, mod - 2) % mod + m;
		int ss3 = s3 + m + m * s2 % mod * quickpow(s1, mod - 2) % mod;
		s1 = ss1 % mod;
		s2 = ss2 % mod;
		s3 = ss3 % mod; 
	}
	cout << s3 << endl;
}
signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--){
		slove();
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 127ms
memory: 3660kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1436ms
memory: 3668kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

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

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: -100
Time Limit Exceeded

input:

28 7304152

output:

457266679

result: