QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155629#6417. Classical Summation ProblemForever_Young#WA 1ms3540kbC++14830b2023-09-01 22:14:382023-09-01 22:14:38

Judging History

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

  • [2023-09-01 22:14:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3540kb
  • [2023-09-01 22:14:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
LL fastpo(LL x, LL n, LL mod) {
	x %= mod;
	LL res = 1;
	while(n) {
		if(n % 2 == 1) {
			res = (res * x) % mod;
		}
		x = x * x % mod;
		n /= 2;
	}
	return res;
}
int main() {
	LL n, k;
	cin >> n >> k;
	LL inv2 = (mod + 1) / 2;
	LL ans = 0;
	if(k % 2 == 1) {
		ans = fastpo(n, k, mod);
		ans = (ans * (1 + n)) % mod;
		ans = ans * inv2 % mod;
	}else {
		ans = fastpo(n, k, mod);
		ans = (ans * (1 + n)) % mod;
		ans = ans * inv2 % mod;
		LL tmp = 0;
		for(int j = 1; j <= n - 1; j++) {
			tmp = tmp + fastpo(j, k / 2, mod) * fastpo(n - j, k / 2, mod);
			tmp = tmp % mod;
		}
		//cout << ans << ' ' << tmp << endl;
		ans = (ans - tmp) % mod;
		ans = (ans + mod) % mod;
	}
	cout << ans << endl;
}

詳細信息

Test #1:

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

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3388kb

input:

5 3

output:

375

result:

ok 1 number(s): "375"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

2 2

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

10 9

output:

508778235

result:

ok 1 number(s): "508778235"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3372kb

input:

69 3

output:

11497815

result:

ok 1 number(s): "11497815"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3376kb

input:

994 515

output:

33689623

result:

ok 1 number(s): "33689623"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3352kb

input:

4476 6182

output:

654114565

result:

wrong answer 1st numbers differ - expected: '114894183', found: '654114565'