QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588792 | #6417. Classical Summation Problem | Tobo# | WA | 0ms | 3856kb | C++20 | 2.8kb | 2024-09-25 14:34:25 | 2024-09-25 14:34:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <int mod>
unsigned int down(unsigned int x)
{
return x >= mod ? x - mod : x;
}
template <int mod>
struct Modint
{
unsigned int x;
Modint() = default;
Modint(unsigned int x) : x(x) {}
friend istream &operator>>(istream &in, Modint &a) { return in >> a.x; }
friend ostream &operator<<(ostream &out, Modint a) { return out << a.x; }
friend Modint operator+(Modint a, Modint b) { return down<mod>(a.x + b.x); }
friend Modint operator-(Modint a, Modint b) { return down<mod>(a.x - b.x + mod); }
friend Modint operator*(Modint a, Modint b) { return 1ULL * a.x * b.x % mod; }
friend Modint operator/(Modint a, Modint b) { return a * ~b; }
friend Modint operator^(Modint a, int b)
{
Modint ans = 1;
for (; b; b >>= 1, a *= a)
if (b & 1)
ans *= a;
return ans;
}
friend Modint operator~(Modint a) { return a ^ (mod - 2); }
friend Modint operator-(Modint a) { return down<mod>(mod - a.x); }
friend Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
friend Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
friend Modint &operator*=(Modint &a, Modint b) { return a = a * b; }
friend Modint &operator/=(Modint &a, Modint b) { return a = a / b; }
friend Modint &operator^=(Modint &a, int b) { return a = a ^ b; }
friend Modint &operator++(Modint &a) { return a += 1; }
friend Modint operator++(Modint &a, int)
{
Modint x = a;
a += 1;
return x;
}
friend Modint &operator--(Modint &a) { return a -= 1; }
friend Modint operator--(Modint &a, int)
{
Modint x = a;
a -= 1;
return x;
}
friend bool operator==(Modint a, Modint b) { return a.x == b.x; }
friend bool operator!=(Modint a, Modint b) { return !(a == b); }
};
const int mod = 998244353;
typedef Modint<mod> mint;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
if (k & 1)
{
mint ans = mint(n) ^ k;
ans *= (n + 1);
ans /= 2;
cout << ans << '\n';
exit(0);
}
vector<mint> fac(n + 1), ifac(n + 1);
fac[0] = ifac[0] = 1;
for (int i = 1; i <= n; i++)
{
fac[i] = fac[i - 1] * i;
ifac[i] = mint(1) / fac[i];
}
auto binom = [&](int x, int y) -> mint
{
return fac[x] * ifac[y] * ifac[x - y];
};
mint sum = 0;
for (int i = 2; i <= n; i++)
{
mint tmp = binom(k, k / 2);
tmp *= mint(i - 1) ^ (k / 2);
tmp *= mint(n - i + 1) ^ (k / 2);
sum -= tmp;
}
sum /= mint(n) ^ k;
sum += n + 1;
sum /= 2;
sum *= mint(n) ^ k;
cout << sum << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
4476 6182
output:
314699348
result:
wrong answer 1st numbers differ - expected: '114894183', found: '314699348'