QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#174360 | #6417. Classical Summation Problem | alexzhanUS | WA | 2ms | 3720kb | C++17 | 2.1kb | 2023-09-10 06:51:17 | 2023-09-10 06:51:18 |
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;
}
if (value % 2 == 0) {
value /= 2;
} else {
value = (value + modulo) / 2;
}
answer -= value;
answer %= modulo;
if (answer < 0) {
answer += modulo;
}
cout << answer << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3668kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3600kb
input:
4476 6182
output:
480411085
result:
wrong answer 1st numbers differ - expected: '114894183', found: '480411085'