QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132489 | #6417. Classical Summation Problem | cciafrino# | WA | 1ms | 3572kb | C++14 | 2.4kb | 2023-07-30 00:31:59 | 2023-07-30 00:32:00 |
Judging History
answer
#include<bits/stdc++.h>
namespace std {
template<unsigned M_> struct modnum {
static constexpr unsigned M = M_;
using ll = long long; using ull = unsigned long long;
unsigned x;
constexpr modnum() : x(0U) {}
constexpr modnum(int a) : x(((a %= static_cast<int>(M)) < 0) ? (a + static_cast<int>(M)) : a) {}
constexpr modnum(unsigned a) : x(a%M) {}
constexpr modnum(ll a) : x(((a %= static_cast<ll>(M)) < 0) ? (a + static_cast<ll>(M)) : a) {}
explicit operator int() const { return x; }
modnum& operator +=(const modnum& a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
modnum& operator -=(const modnum& a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
modnum& operator *=(const modnum& a) { x = unsigned((static_cast<ull>(x) * a.x) % M); return *this; }
modnum& operator /=(const modnum& a) { return (*this *= a.inv()); }
modnum operator +(const modnum& a) const { return modnum(*this) += a; }
modnum operator -(const modnum& a) const { return modnum(*this) -= a; }
modnum operator *(const modnum& a) const { return modnum(*this) *= a; }
modnum operator /(const modnum& a) const { return modnum(*this) /= a; }
modnum operator +() const { return *this; }
modnum operator -() const { modnum a; a.x = x ? (M-x) : 0U; return a; }
modnum pow(ll e) const {
modnum x2 = x, xe = 1U;
for (; e; e >>= 1) {
if (e & 1) xe *= x2;
x2 *= x2;
}
return xe;
}
modnum inv() const {
unsigned a = x, b = M; int y = 1, z = 0;
while (a) {
const unsigned q = (b/a), c = (b - q*a);
b = a, a = c;
const int w = z - static_cast<int>(q) * y;
z = y, y = w;
}
return modnum(z);
}
};
}
int main() {
using namespace std;
cin.tie(nullptr)->sync_with_stdio(false);
int N, K; cin >> N >> K;
using num = modnum<998244353>;
if (K & 1) {
cout << (num(N).pow(K) * num(N + 1) / 2).x << '\n';
} else {
num S = 0;
for (int x = 0; x <= 2*N; ++x) {
if (2*x < N) {
S += num(N).pow(K) - num(K).pow(K/2) * num(x).pow(K/2) * num(N-x).pow(K/2);
} else {
for (int i = 1; i < K/2; ++i) {
S += num(K).pow(i) * num(x).pow(i) * num(N-x).pow(K-i);
}
}
}
cout << S.x << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3408kb
input:
2 2
output:
4
result:
wrong answer 1st numbers differ - expected: '5', found: '4'