QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#174356 | #6417. Classical Summation Problem | alexzhanUS | WA | 3ms | 3668kb | C++17 | 2.0kb | 2023-09-10 06:48:40 | 2023-09-10 06:48:40 |
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;
long long answer = (n + 1);
for (int i = 0; i < k; i++) {
answer *= n;
answer %= modulo;
}
if (answer % 2 == 0) {
answer /= 2;
} else {
answer = (answer + modulo) / 2;
}
if (k % 2 == 1) {
cout << answer << "\n";
} 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 value = 0;
for (int i = 1; i < n; i++) {
long long tmp = binaryExponentiation(i, k/2);
tmp *= binaryExponentiation(n - i, k/2);
tmp %= modulo;
tmp *= combination;
tmp %= modulo;
value += tmp;
}
answer -= value / 2;
answer %= modulo;
if (answer < 0) {
answer += modulo;
}
cout << answer << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3660kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: -100
Wrong Answer
time: 3ms
memory: 3644kb
input:
4476 6182
output:
979533262
result:
wrong answer 1st numbers differ - expected: '114894183', found: '979533262'