QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700285 | #9515. 无限地狱 | TheZone | 17 | 1ms | 4116kb | C++23 | 4.7kb | 2024-11-02 12:38:14 | 2024-11-02 12:38:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
int main() {
Int N;
for (; ~scanf("%lld", &N); ) {
vector<Mint> P(N + 1, 0);
for (int n = 2; n <= N; ++n) {
vector<Mint> hs(n, 0);
for (int d = 1; d < n; ++d) {
hs[d] = 1;
for (int i = 1; i <= n - i; ++i) {
bool canB = true;
canB = canB && (i != 1);
canB = canB && (i % d == 0);
canB = canB && ((n - i) % d == 0);
if (canB) hs[d] *= 2;
}
hs[d] -= 1;
}
for (int d = n - 1; d >= 1; --d) for (int e = 2 * d; e < n; e += d) hs[d] -= hs[e];
P[n] = hs[1];
}
vector<Mint> F1(N + 1, 0), F2(N + 1, 0), F3(N + 1, 0);
vector<Mint> G2(N + 1, 0), G3(N + 1, 0);
for (int n = 1; n <= N; ++n) {
F1[n] = 1;
F2[n] = (Mint(2).pow(n) - 2) / 2;
{
vector<Mint> hs(n + 1, 0);
for (int d = 1; d <= n; ++d) {
hs[d] = 1;
for (int i = 1; i <= n; ++i) {
bool canB = true;
canB = canB && (i != 1);
canB = canB && (i % d == 0);
if (canB) hs[d] *= 2;
}
hs[d] -= 1;
}
for (int d = n; d >= 1; --d) for (int e = 2 * d; e <= n; e += d) hs[d] -= hs[e];
G2[n] = hs[1];
}
for (int g = 2; g <= n; ++g) {
F3[n] += F1[g/2] * (G2[n/g] + G3[n/g]);
F3[n] += F2[g/2] * (F1[n/g] + 2*G2[n/g] + 2*F2[n/g] + 2*G3[n/g] + 2*F3[n/g]);
G3[n] += P[g] * (F1[n/g] + 2*G2[n/g] + 2*F2[n/g] + 2*G3[n/g] + 2*F3[n/g]);
}
}
const Mint ans = F1[N] + F2[N] + F3[N];
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 0ms
memory: 3892kb
input:
6
output:
38
result:
ok 1 number(s): "38"
Test #2:
score: 4
Accepted
time: 1ms
memory: 3772kb
input:
7
output:
73
result:
ok 1 number(s): "73"
Test #3:
score: 4
Accepted
time: 0ms
memory: 3768kb
input:
8
output:
148
result:
ok 1 number(s): "148"
Test #4:
score: 4
Accepted
time: 0ms
memory: 3788kb
input:
9
output:
284
result:
ok 1 number(s): "284"
Test #5:
score: 4
Accepted
time: 0ms
memory: 3820kb
input:
10
output:
565
result:
ok 1 number(s): "565"
Subtask #2:
score: 13
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 13
Accepted
time: 0ms
memory: 4116kb
input:
30
output:
536938322
result:
ok 1 number(s): "536938322"
Test #7:
score: 13
Accepted
time: 0ms
memory: 3824kb
input:
35
output:
210046687
result:
ok 1 number(s): "210046687"
Test #8:
score: 13
Accepted
time: 0ms
memory: 3876kb
input:
38
output:
680532913
result:
ok 1 number(s): "680532913"
Test #9:
score: 13
Accepted
time: 0ms
memory: 3824kb
input:
39
output:
362030079
result:
ok 1 number(s): "362030079"
Test #10:
score: 13
Accepted
time: 0ms
memory: 3824kb
input:
40
output:
723529503
result:
ok 1 number(s): "723529503"
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #11:
score: 0
Time Limit Exceeded
input:
2000
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%