#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &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 void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } //////////////////////////////////////////////////////////////////////////////// template 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(M)) < 0) ? (x_ + static_cast(M)) : x_) {} constexpr ModInt(long long x_) : x(((x_ %= static_cast(M)) < 0) ? (x_ + static_cast(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(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(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 friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); } template friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); } template friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); } template 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; } }; //////////////////////////////////////////////////////////////////////////////// // 0 = \sum_{j=0}^d (\sum_{k=0}^e css[j][k] i^k) as[i - j] (d <= i < |as|) template vector>> findPRecurrence(const vector> &as, int e, bool verbose = false) { using Mint = ModInt; const int asLen = as.size(); // asLen - d >= (d + 1) (e + 1) - 1 (otherwise definitely dim Ker >= 2) const int d0 = (asLen + 2) / (e + 2) - 1; if (d0 < 0) { if (verbose) { fprintf(stderr, "[findPRecurrence] |as| >= e must hold.\n"); fflush(stderr); } return {}; } const int m = asLen - d0, n = (d0 + 1) * (e + 1); vector> bss(m, vector(n, 0)); for (int i = d0; i < asLen; ++i) for (int j = 0; j <= d0; ++j) { Mint pw = 1; for (int k = 0; k <= e; ++k) { bss[i - d0][j * (e + 1) + k] = pw * as[i - j]; pw *= i; } } int r = 0; vector hs; for (int h = 0; h < n; ++h) { for (int i = r; i < m; ++i) if (bss[i][h]) { bss[r].swap(bss[i]); break; } if (r < m && bss[r][h]) { const Mint s = bss[r][h].inv(); for (int j = h; j < n; ++j) bss[r][j] *= s; for (int i = 0; i < m; ++i) if (i != r) { const Mint t = bss[i][h]; for (int j = h; j < n; ++j) bss[i][j] -= t * bss[r][j]; } ++r; } else { hs.push_back(h); } } if (hs.empty()) { if (verbose) { fprintf(stderr, "[findPRecurrence] Not found: d = %d, e = %d.\n", d0, e); fflush(stderr); } return {}; } vector> css(d0 + 1, vector(e + 1, 0)); for (int j = 0; j <= d0; ++j) for (int k = 0; k <= e; ++k) { const int h = j * (e + 1) + k; css[j][k] = (h < hs[0]) ? -bss[h][hs[0]] : (h == hs[0]) ? 1 : 0; } int d = hs[0] / (e + 1); for (int i = d0; i < asLen; ++i) { Mint sum = 0; for (int j = 0; j <= d0; ++j) { Mint coef = 0, pw = 1; for (int k = 0; k <= e; ++k) { coef += css[j][k] * pw; pw *= i; } sum += coef * as[i - j]; } for (; sum; ) { if (i - ++d < 0) break; assert(d <= d0); Mint coef = 0, pw = 1; for (int k = 0; k <= e; ++k) { coef += css[d][k] * pw; pw *= i; } sum += coef * as[i - d]; } } css.resize(d + 1); if (verbose) { const int hsLen = hs.size(); if (hsLen > d0 - d + 1) { fprintf(stderr, "[findPRecurrence] Degenerate? (dim Ker = %d)\n", hsLen); } fprintf(stderr, "[findPRecurrence] d = %d, e = %d, non-trivial: %d\n", d, e, asLen - d - (d + 1) * (e + 1) + 1); fprintf(stderr, "{\n"); for (int j = 0; j <= d; ++j) { fprintf(stderr, " {"); for (int k = 0; k <= e; ++k) { const unsigned c = css[j][k].x; if (k > 0) fprintf(stderr, ", "); fprintf(stderr, "%d", static_cast((c < M - c) ? c : (c - M))); } fprintf(stderr, "},\n"); } fprintf(stderr, "}\n"); fflush(stderr); } return css; } // 0 = \sum_{j=0}^d (\sum_{k=0}^e css[j][k] i^k) as[i - j] (d <= i < |as|) template vector> extendPRecurrence(vector> as, const vector>> &css, int n) { using Mint = ModInt; assert(!css.empty()); const int d = css.size() - 1, e = css[0].size() - 1; for (int j = 0; j <= d; ++j) assert(static_cast(css[j].size()) == e + 1); const int asLen = as.size(); as.resize(n); for (int i = asLen; i < n; ++i) { Mint sum = 0; for (int j = 1; j <= d; ++j) { Mint coef = 0, pw = 1; for (int k = 0; k <= e; ++k) { coef += css[j][k] * pw; pw *= i; } sum += coef * as[i - j]; } { Mint coef = 0, pw = 1; for (int k = 0; k <= e; ++k) { coef += css[0][k] * pw; pw *= i; } as[i] = -sum / coef; } } return as; } //////////////////////////////////////////////////////////////////////////////// constexpr unsigned MO = 998244353; using Mint = ModInt; constexpr int M = 100; Mint c[M][M]; int main() { for (int n = 0; n < M; ++n) { c[n][0] = 0; c[n][n] = 1; for (int k = 1; k < n; ++k) { c[n][k] = c[n - 1][k - 1] + (n - 1) * c[n - 1][k]; } } vector as(M); for (int n = 0; n < M; ++n) { for (int k = 0; k <= n; ++k) { as[n] += c[n][k] * k * k * k; } } cerr<<"as = "<