# Submit Info #288

Problem Lang User Status Time Memory
Partition Function cpp pekempey AC 2869 ms 131.75 MiB

ケース詳細
Name Status Time Memory
0_00 AC 92 ms 32.67 MiB
100000_00 AC 688 ms 59.89 MiB
10000_00 AC 163 ms 35.77 MiB
1000_00 AC 96 ms 32.92 MiB
100_00 AC 93 ms 32.71 MiB
1_00 AC 94 ms 32.75 MiB
200000_00 AC 1344 ms 80.66 MiB
300000_00 AC 2841 ms 129.48 MiB
400000_00 AC 2842 ms 130.60 MiB
500000_00 AC 2869 ms 131.75 MiB
example_00 AC 93 ms 32.67 MiB

#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; constexpr int MOD = 998244353; class mint { int n; public: mint(int n_ = 0) : n(n_) {} explicit operator int() { return n; } friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); } friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; } friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; } friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; } friend mint &operator+=(mint &a, mint b) { return a = a + b; } friend mint &operator-=(mint &a, mint b) { return a = a - b; } friend mint &operator*=(mint &a, mint b) { return a = a * b; } friend bool operator==(mint a, mint b) { return a.n == b.n; } friend bool operator!=(mint a, mint b) { return a.n != b.n; } friend istream &operator>>(istream &i, mint &a) { return i >> a.n; } friend ostream &operator<<(ostream &o, mint a) { return o << a.n; } }; mint operator "" _m(unsigned long long n) { return n; } mint modpow(mint a, long long b) { mint res = 1; while (b > 0) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } mint modinv(mint n) { int a = (int)n, b = MOD; int s = 1, t = 0; while (b != 0) { int q = a / b; a -= q * b; s -= q * t; swap(a, b); swap(s, t); } return s >= 0 ? s : s + MOD; } template<int N> struct FFT { complex<double> rots[N]; FFT() { const double pi = acos(-1); for (int i = 0; i < N / 2; i++) { rots[i + N / 2].real(cos(2 * pi / N * i)); rots[i + N / 2].imag(sin(2 * pi / N * i)); } for (int i = N / 2 - 1; i >= 1; i--) { rots[i] = rots[i * 2]; } } inline complex<double> mul(complex<double> a, complex<double> b) { return complex<double>( a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real() ); } void fft(vector<complex<double>> &a, bool rev) { const int n = a.size(); int i = 0; for (int j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1); if (j < i) { swap(a[i], a[j]); } } for (int i = 1; i < n; i *= 2) { for (int j = 0; j < n; j += i * 2) { for (int k = 0; k < i; k++) { auto s = a[j + k + 0]; auto t = mul(a[j + k + i], rots[i + k]); a[j + k + 0] = s + t; a[j + k + i] = s - t; } } } if (rev) { reverse(a.begin() + 1, a.end()); for (int i = 0; i < n; i++) { a[i] *= 1.0 / n; } } } vector<long long> convolution(vector<long long> a, vector<long long> b) { int t = 1; while (t < a.size() + b.size() - 1) t *= 2; vector<complex<double>> z(t); for (int i = 0; i < a.size(); i++) z[i].real(a[i]); for (int i = 0; i < b.size(); i++) z[i].imag(b[i]); fft(z, false); vector<complex<double>> w(t); for (int i = 0; i < t; i++) { auto p = (z[i] + conj(z[(t - i) % t])) * complex<double>(0.5, 0); auto q = (z[i] - conj(z[(t - i) % t])) * complex<double>(0, -0.5); w[i] = p * q; } fft(w, true); vector<long long> ans(a.size() + b.size() - 1); for (int i = 0; i < ans.size(); i++) { ans[i] = round(w[i].real()); } return ans; } vector<mint> convolution(vector<mint> a, vector<mint> b) { int t = 1; while (t < a.size() + b.size() - 1) t *= 2; vector<complex<double>> A(t), B(t); for (int i = 0; i < a.size(); i++) A[i] = complex<double>((int)a[i] & 0x7fff, (int)a[i] >> 15); for (int i = 0; i < b.size(); i++) B[i] = complex<double>((int)b[i] & 0x7fff, (int)b[i] >> 15); fft(A, false); fft(B, false); vector<complex<double>> C(t), D(t); for (int i = 0; i < t; i++) { int j = (t - i) % t; auto AL = (A[i] + conj(A[j])) * complex<double>(0.5, 0); auto AH = (A[i] - conj(A[j])) * complex<double>(0, -0.5); auto BL = (B[i] + conj(B[j])) * complex<double>(0.5, 0); auto BH = (B[i] - conj(B[j])) * complex<double>(0, -0.5); C[i] = AL * BL + AH * BL * complex<double>(0, 1); D[i] = AL * BH + AH * BH * complex<double>(0, 1); } fft(C, true); fft(D, true); vector<mint> ans(a.size() + b.size() - 1); for (int i = 0; i < ans.size(); i++) { long long l = (long long)round(C[i].real()) % MOD; long long m = ((long long)round(C[i].imag()) + (long long)round(D[i].real())) % MOD; long long h = (long long)round(D[i].imag()) % MOD; ans[i] = (l + (m << 15) + (h << 30)) % MOD; } return ans; } }; FFT<1 << 21> fft; typedef vector<mint> poly; poly operator-(poly a) { for (int i = 0; i < a.size(); i++) { a[i] = -a[i]; } return a; } poly operator+(poly a, poly b) { for (int i = 0; i < a.size(); i++) { a[i] += b[i]; } return a; } poly operator-(poly a, poly b) { for (int i = 0; i < a.size(); i++) { a[i] -= b[i]; } return a; } poly &operator+=(poly &a, poly b) { return a = a + b; } poly &operator-=(poly &a, poly b) { return a = a - b; } poly pinv(poly a) { const int n = a.size(); poly x = {modinv(a[0])}; for (int i = 1; i < n; i *= 2) { vector<mint> tmp(min(i * 2, n)); for (int j = 0; j < tmp.size(); j++) { tmp[j] = a[j]; } auto e = -fft.convolution(tmp, x); e[0] += 2; x = fft.convolution(x, e); x.resize(i * 2); } x.resize(n); return x; } poly plog(poly a) { const int n = a.size(); vector<mint> b(n); for (int i = 1; i < n; i++) { b[i - 1] = i * a[i]; } a = fft.convolution(pinv(a), b); for (int i = n - 1; i >= 1; i--) { a[i] = modinv(i) * a[i - 1]; } a[0] = 0; a.resize(n); return a; } // g = exp(f(x)) // log g - f(x) = 0 // g - g * (log g - f(x))) // g * (1 - log g + f(x)) poly pexp(poly a) { const int n = a.size(); poly x = {1}; for (int i = 1; i < n; i *= 2) { x.resize(i * 2); auto e = -plog(x); e[0] += 1; for (int j = 0; j < min<int>(n, e.size()); j++) { e[j] += a[j]; } x = fft.convolution(x, e); x.resize(i * 2); } x.resize(n); return x; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; N++; // (1+x+x^2+...)(1+x^2+x^4+...) // 1/(1-x) 1/(1-x^2) // -log(1-x) -log(1-x^2) - ... vector<mint> I(N); I[1] = 1; for (int i = 2; i < N; i++) { I[i] = I[MOD % i] * (MOD - MOD / i); } vector<mint> f(N); for (int i = 1; i < N; i++) { for (int j = 1; i * j < N; j++) { f[i * j] += I[j]; } } f = pexp(f); rep(i, N) cout << f[i] << " \n"[i == N - 1]; }