QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#174343 | #6417. Classical Summation Problem | alexzhanUS | WA | 2ms | 3712kb | C++17 | 1.8kb | 2023-09-10 06:38:37 | 2023-09-10 06:38:38 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
long long modulo = 998244353;
long long binaryExponentiation(long long value, long long power) {
vector<long long> powers(31);
powers[0] = value;
for (int i = 1; i <= 30; i++) {
powers[i] = powers[i - 1] * powers[i - 1];
powers[i] %= modulo;
}
long long answer = 1;
for (int i = 0; i <= 30; i++) {
if ((power & (1 << i)) > 0) {
answer *= powers[i];
answer %= modulo;
}
}
return answer;
}
long long divide(long long a, long long b) {
// find a/b mod modulo
// find b ^ (modulo - 2)
long long inverse = binaryExponentiation(b, modulo - 2);
return ((inverse * a) % modulo);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
if (k % 2 == 1) {
long long answer = (n + 1) / 2;
for (int i = 0; i < k; i++) {
answer *= n;
answer %= modulo;
}
cout << answer;
} else {
long long factorial1 = 1;
for (int i = 1; i <= k / 2; i++) {
factorial1 *= i;
factorial1 %= modulo;
}
long long factorial2 = 1;
for (int i = 1; i <= k; i++) {
factorial1 *= i;
factorial1 %= modulo;
}
long long combination = factorial1;
combination = divide(combination, factorial2);
combination = divide(combination, factorial2);
long long answer = 0;
for (int i = 1; i < n; i++) {
long long tmp = binaryExponentiation(i, k/2);
tmp *= binaryExponentiation(n + 1 - i, k/2);
tmp %= modulo;
tmp *= combination;
tmp %= modulo;
answer += tmp;
}
cout << answer;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3652kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
input:
2 2
output:
4
result:
wrong answer 1st numbers differ - expected: '5', found: '4'