QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225936#7609. Colonizationhos_lyricAC ✓18ms4348kbC++1423.5kb2023-10-25 12:34:152023-10-25 12:34:15

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 12:34:15]
  • 评测
  • 测评结果:AC
  • 用时:18ms
  • 内存:4348kb
  • [2023-10-25 12:34:15]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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; }
};
////////////////////////////////////////////////////////////////////////////////


#define ModInt Mint
////////////////////////////////////////////////////////////////////////////////
// Barrett
struct ModInt {
  static unsigned M;
  static unsigned long long NEG_INV_M;
  static void setM(unsigned m) { M = m; NEG_INV_M = -1ULL / M; }
  unsigned x;
  ModInt() : x(0U) {}
  ModInt(unsigned x_) : x(x_ % M) {}
  ModInt(unsigned long long x_) : x(x_ % M) {}
  ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  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) {
    const unsigned long long y = static_cast<unsigned long long>(x) * a.x;
    const unsigned long long q = static_cast<unsigned long long>((static_cast<unsigned __int128>(NEG_INV_M) * y) >> 64);
    const unsigned long long r = y - M * q;
    x = r - M * (r >= 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; }
};
unsigned ModInt::M;
unsigned long long ModInt::NEG_INV_M;
// !!!Use ModInt::setM!!!
////////////////////////////////////////////////////////////////////////////////
#undef ModInt

constexpr int LIM_INV = 2010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];

void prepare() {
  inv[1] = 1;
  for (int i = 2; i < LIM_INV; ++i) {
    inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
  }
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < LIM_INV; ++i) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(Int n, Int k) {
  if (n < 0) {
    if (k >= 0) {
      return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
    } else if (n - k >= 0) {
      return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
    } else {
      return 0;
    }
  } else {
    if (0 <= k && k <= n) {
      assert(n < LIM_INV);
      return fac[n] * invFac[k] * invFac[n - k];
    } else {
      return 0;
    }
  }
}


////////////////////////////////////////////////////////////////////////////////
// M: prime, G: primitive root, 2^K | M - 1
template <unsigned M_, unsigned G_, int K_> struct Fft {
  static_assert(2U <= M_, "Fft: 2 <= M must hold.");
  static_assert(M_ < 1U << 30, "Fft: M < 2^30 must hold.");
  static_assert(1 <= K_, "Fft: 1 <= K must hold.");
  static_assert(K_ < 30, "Fft: K < 30 must hold.");
  static_assert(!((M_ - 1U) & ((1U << K_) - 1U)), "Fft: 2^K | M - 1 must hold.");
  static constexpr unsigned M = M_;
  static constexpr unsigned M2 = 2U * M_;
  static constexpr unsigned G = G_;
  static constexpr int K = K_;
  ModInt<M> FFT_ROOTS[K + 1], INV_FFT_ROOTS[K + 1];
  ModInt<M> FFT_RATIOS[K], INV_FFT_RATIOS[K];
  Fft() {
    const ModInt<M> g(G);
    for (int k = 0; k <= K; ++k) {
      FFT_ROOTS[k] = g.pow((M - 1U) >> k);
      INV_FFT_ROOTS[k] = FFT_ROOTS[k].inv();
    }
    for (int k = 0; k <= K - 2; ++k) {
      FFT_RATIOS[k] = -g.pow(3U * ((M - 1U) >> (k + 2)));
      INV_FFT_RATIOS[k] = FFT_RATIOS[k].inv();
    }
    assert(FFT_ROOTS[1] == M - 1U);
  }
  // as[rev(i)] <- \sum_j \zeta^(ij) as[j]
  void fft(ModInt<M> *as, int n) const {
    assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
    int m = n;
    if (m >>= 1) {
      for (int i = 0; i < m; ++i) {
        const unsigned x = as[i + m].x;  // < M
        as[i + m].x = as[i].x + M - x;  // < 2 M
        as[i].x += x;  // < 2 M
      }
    }
    if (m >>= 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned x = (prod * as[i + m]).x;  // < M
          as[i + m].x = as[i].x + M - x;  // < 3 M
          as[i].x += x;  // < 3 M
        }
        prod *= FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
    for (; m; ) {
      if (m >>= 1) {
        ModInt<M> prod = 1U;
        for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
          for (int i = i0; i < i0 + m; ++i) {
            const unsigned x = (prod * as[i + m]).x;  // < M
            as[i + m].x = as[i].x + M - x;  // < 4 M
            as[i].x += x;  // < 4 M
          }
          prod *= FFT_RATIOS[__builtin_ctz(++h)];
        }
      }
      if (m >>= 1) {
        ModInt<M> prod = 1U;
        for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
          for (int i = i0; i < i0 + m; ++i) {
            const unsigned x = (prod * as[i + m]).x;  // < M
            as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
            as[i + m].x = as[i].x + M - x;  // < 3 M
            as[i].x += x;  // < 3 M
          }
          prod *= FFT_RATIOS[__builtin_ctz(++h)];
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
      as[i].x = (as[i].x >= M) ? (as[i].x - M) : as[i].x;  // < M
    }
  }
  // as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
  void invFft(ModInt<M> *as, int n) const {
    assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
    int m = 1;
    if (m < n >> 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned long long y = as[i].x + M - as[i + m].x;  // < 2 M
          as[i].x += as[i + m].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
      }
      m <<= 1;
    }
    for (; m < n >> 1; m <<= 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + (m >> 1); ++i) {
          const unsigned long long y = as[i].x + M2 - as[i + m].x;  // < 4 M
          as[i].x += as[i + m].x;  // < 4 M
          as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
          const unsigned long long y = as[i].x + M - as[i + m].x;  // < 2 M
          as[i].x += as[i + m].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
    if (m < n) {
      for (int i = 0; i < m; ++i) {
        const unsigned y = as[i].x + M2 - as[i + m].x;  // < 4 M
        as[i].x += as[i + m].x;  // < 4 M
        as[i + m].x = y;  // < 4 M
      }
    }
    const ModInt<M> invN = ModInt<M>(n).inv();
    for (int i = 0; i < n; ++i) {
      as[i] *= invN;
    }
  }
  void fft(vector<ModInt<M>> &as) const {
    fft(as.data(), as.size());
  }
  void invFft(vector<ModInt<M>> &as) const {
    invFft(as.data(), as.size());
  }
  vector<ModInt<M>> convolve(vector<ModInt<M>> as, vector<ModInt<M>> bs) const {
    if (as.empty() || bs.empty()) return {};
    const int len = as.size() + bs.size() - 1;
    int n = 1;
    for (; n < len; n <<= 1) {}
    as.resize(n); fft(as);
    bs.resize(n); fft(bs);
    for (int i = 0; i < n; ++i) as[i] *= bs[i];
    invFft(as);
    as.resize(len);
    return as;
  }
  vector<ModInt<M>> square(vector<ModInt<M>> as) const {
    if (as.empty()) return {};
    const int len = as.size() + as.size() - 1;
    int n = 1;
    for (; n < len; n <<= 1) {}
    as.resize(n); fft(as);
    for (int i = 0; i < n; ++i) as[i] *= as[i];
    invFft(as);
    as.resize(len);
    return as;
  }
};

// M0 M1 M2 = 789204840662082423367925761 (> 7.892 * 10^26, > 2^89)
// M0 M3 M4 M5 M6 = 797766583174034668024539679147517452591562753 (> 7.977 * 10^44, > 2^149)
const Fft<998244353U, 3U, 23> FFT0;
const Fft<897581057U, 3U, 23> FFT1;
const Fft<880803841U, 26U, 23> FFT2;
const Fft<985661441U, 3U, 22> FFT3;
const Fft<943718401U, 7U, 22> FFT4;
const Fft<935329793U, 3U, 22> FFT5;
const Fft<918552577U, 5U, 22> FFT6;

// T = unsigned, unsigned long long, ModInt<M>
template <class T, unsigned M0, unsigned M1, unsigned M2>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2) {
  static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
  static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
  const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
  const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
  return (T(b2.x) * M1 + b1.x) * M0 + a0.x;
}
template <class T, unsigned M0, unsigned M1, unsigned M2, unsigned M3, unsigned M4>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2, ModInt<M3> a3, ModInt<M4> a4) {
  static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
  static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
  static const ModInt<M3> INV_M0M1M2_M3 = (ModInt<M3>(M0) * M1 * M2).inv();
  static const ModInt<M4> INV_M0M1M2M3_M4 = (ModInt<M4>(M0) * M1 * M2 * M3).inv();
  const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
  const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
  const ModInt<M3> b3 = INV_M0M1M2_M3 * (a3 - ((ModInt<M3>(b2.x) * M1 + b1.x) * M0 + a0.x));
  const ModInt<M4> b4 = INV_M0M1M2M3_M4 * (a4 - (((ModInt<M4>(b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x));
  return (((T(b4.x) * M3 + b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x;
}

template <unsigned M> vector<ModInt<M>> convolve(const vector<ModInt<M>> &as, const vector<ModInt<M>> &bs) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty() || bs.empty()) return {};
  const int asLen = as.size(), bsLen = bs.size();
  vector<ModInt<M0>> as0(asLen), bs0(bsLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs0[i] = bs[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.convolve(as0, bs0);
  vector<ModInt<M1>> as1(asLen), bs1(bsLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs1[i] = bs[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.convolve(as1, bs1);
  vector<ModInt<M2>> as2(asLen), bs2(bsLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs2[i] = bs[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.convolve(as2, bs2);
  vector<ModInt<M>> cs(asLen + bsLen - 1);
  for (int i = 0; i < asLen + bsLen - 1; ++i) {
    cs[i] = garner<ModInt<M>>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}
template <unsigned M> vector<ModInt<M>> square(const vector<ModInt<M>> &as) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty()) return {};
  const int asLen = as.size();
  vector<ModInt<M0>> as0(asLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.square(as0);
  vector<ModInt<M1>> as1(asLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.square(as1);
  vector<ModInt<M2>> as2(asLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.square(as2);
  vector<ModInt<M>> cs(asLen + asLen - 1);
  for (int i = 0; i < asLen + asLen - 1; ++i) {
    cs[i] = garner<ModInt<M>>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}
////////////////////////////////////////////////////////////////////////////////

vector<Mint> convolve(const vector<Mint> &as, const vector<Mint> &bs) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty() || bs.empty()) return {};
  const int asLen = as.size(), bsLen = bs.size();
  vector<ModInt<M0>> as0(asLen), bs0(bsLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs0[i] = bs[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.convolve(as0, bs0);
  vector<ModInt<M1>> as1(asLen), bs1(bsLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs1[i] = bs[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.convolve(as1, bs1);
  vector<ModInt<M2>> as2(asLen), bs2(bsLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs2[i] = bs[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.convolve(as2, bs2);
  vector<Mint> cs(asLen + bsLen - 1);
  for (int i = 0; i < asLen + bsLen - 1; ++i) {
    cs[i] = garner<Mint>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}
vector<Mint> square(const vector<Mint> &as) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty()) return {};
  const int asLen = as.size();
  vector<ModInt<M0>> as0(asLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.square(as0);
  vector<ModInt<M1>> as1(asLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.square(as1);
  vector<ModInt<M2>> as2(asLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.square(as2);
  vector<Mint> cs(asLen + asLen - 1);
  for (int i = 0; i < asLen + asLen - 1; ++i) {
    cs[i] = garner<Mint>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}

vector<Mint> polyInv(const vector<Mint> &as, int n) {
  assert(!as.empty()); assert(as[0]);
  const int asLen = as.size();
  vector<Mint> bs{as[0].inv()};
  for (int m = 1; m < n; m <<= 1) {
    const vector<Mint> as0(as.begin(), as.begin() + min(m << 1, asLen));
    const auto cs = convolve(as0, square(bs));
    bs.resize(m << 1, 0);
    for (int i = m; i < m << 1 && i < (int)cs.size(); ++i) bs[i] -= cs[i];
  }
  return bs;
}

vector<Mint> polyLog(const vector<Mint> &as, int n) {
  assert(!as.empty()); assert(as[0] == 1);
  const int asLen = as.size();
  vector<Mint> bs = as;
  for (int i = 0; i < asLen; ++i) bs[i] *= i;
  bs = convolve(bs, polyInv(as, n));
  bs.resize(n);
  for (int i = 0; i < n; ++i) bs[i] *= inv[i];
  return bs;
}

// O(|as| + n (log n)^2)
vector<Mint> polyExp(vector<Mint> as, int n) {
  assert(!as.empty()); assert(!as[0]);
  const int asLen = as.size();
  for (int i = 0; i < asLen; ++i) as[i] *= i;
  vector<Mint> bs(n, 0);
  bs[0] = 1;
  for (int i = 1; i < n; ++i) {
    const int w = i & -i;
    const vector<Mint> as0(as.begin(), as.begin() + min(w << 1, asLen));
    const vector<Mint> bs0(bs.begin() + (i - w), bs.begin() + i);
    const auto prod = convolve(as0, bs0);
    for (int j = i; j < i + w && j < n && j - (i - w) < (int)prod.size(); ++j) bs[j] += prod[j - (i - w)];
    bs[i] *= inv[i];
  }
  return bs;
}

vector<Mint> polyPow1(const vector<Mint> &as, Mint k, int n) {
  assert(!as.empty()); assert(as[0] == 1);
  vector<Mint> bs = polyLog(as, n);
  for (int i = 0; i < n; ++i) bs[i] *= k;
  return polyExp(bs, n);
}

// [x^n] a/b
Mint polyDivAt(vector<Mint> as, vector<Mint> bs, long long n) {
  const int len = max(as.size(), bs.size());
  as.resize(len, 0);
  bs.resize(len, 0);
  assert(len > 0); assert(bs[0]);
  for (; n >= len; n >>= 1) {
    auto cs = bs;
    for (int i = 1; i < len; i += 2) cs[i] = -cs[i];
    as = convolve(as, cs);
    bs = convolve(bs, cs);
    as.resize(len << 1);
    for (int i = 0; i < len; ++i) as[i] = as[2 * i + (n & 1)];
    for (int i = 0; i < len; ++i) bs[i] = bs[2 * i];
    as.resize(len);
    bs.resize(len);
  }
  bs = polyInv(bs, n + 1);
  Mint ret = 0;
  for (int i = 0; i <= n; ++i) ret += as[i] * bs[n - i];
  return ret;
}

Mint linearRecurrenceAt(const vector<Mint> &as, const vector<Mint> &cs, long long k) {
  assert(!cs.empty()); assert(cs[0]);
  const int d = (int)cs.size() - 1;
  assert((int)as.size() >= d);
  const vector<Mint> as0(as.begin(), as.begin() + d);
  auto bs = convolve(as0, cs);
  bs.resize(d);
  return polyDivAt(bs, cs, k);
}


int N, P;

vector<Mint> MSet(const vector<Mint> &as) {
  assert(!as[0]);
  vector<Mint> bs(N + 1, 0);
  for (int i = 1; i <= N; ++i) for (int j = 1; i * j <= N; ++j) {
    bs[i * j] += inv[i] * as[j];
  }
  return polyExp(bs, N + 1);
}

int main() {
// for(int k=0;k<10;++k)cerr<<k<<": "<<(1+3*((1<<k)-1))<<endl;
  for (; ~scanf("%d%d", &N, &P); ) {
    Mint::setM(P);
    prepare();
    
    vector<Mint> ans(N + 1, 0);
    // x MSet("subtree with rooted DP k"), MSet=1, MSet=2
    vector<Mint> tree(N + 1, 0), tree0(N + 1, 0), tree1(N + 1, 0), tree2(N + 1, 0);
    tree[1] += 1;
    // x MSet1(rooted DP is k)
    for (int k = 0; 1 + 3 * ((1 << k) - 1) <= N; ++k) {
/*
cerr<<COLOR("33")<<"k = "<<k<<COLOR()<<endl;
cerr<<"tree = "<<tree<<endl;
cerr<<"tree0 = "<<tree0<<endl;
cerr<<"tree1 = "<<tree1<<endl;
cerr<<"tree2 = "<<tree2<<endl;
*/
      vector<Mint> multi(N + 1, 0);
      for (int i = 0; i <= N; ++i) {
        multi[i] = (tree[i] - tree0[i] - tree1[i]);
      }
      
      vector<Mint> chain;
      {
        auto tmp = tree;
        for (int i = 0; i <= N; ++i) tmp[i] = -tmp[i];
        tmp[0] += 1;
        chain = polyInv(tmp, N + 1);
      }
      // attach >= 2 at end
      auto chain1 = convolve(chain, multi); chain1.resize(N + 1);
      auto chain2 = convolve(chain1, multi); chain2.resize(N + 1);
      
      vector<Mint> chain1chain1(N + 1, 0);
      for (int i = 1; 2 * i <= N; ++i) chain1chain1[2 * i] = chain1[i];
      
      vector<Mint> good(N + 1, 0);
      // >= 3 "subtrees"
      for (int i = 0; i <= N; ++i) {
        good[i] += (tree[i] - tree0[i] - tree1[i] - tree2[i]);
      }
      // >= 2 "subtrees", chain*, >= 2 "subtrees"
      {
        auto palinEven = chain1chain1;
        auto palinOdd = convolve(chain1chain1, tree); palinOdd.resize(N + 1);
        for (int i = 0; i <= N; ++i) {
          good[i] += (chain2[i] + palinEven[i] + palinOdd[i]) / 2;
        }
      }
// cerr<<"good = "<<good<<endl;
      ans[k + 1] += good[N];
      
      tree0 = tree;
      tree1 = convolve(tree, chain1); tree1.resize(N + 1);
      {
        auto tmp = square(chain1); tmp.resize(N + 1);
        for (int i = 0; i <= N; ++i) {
          tmp[i] = (tmp[i] + chain1chain1[i]) / 2;
        }
        tree2 = convolve(tree, tmp); tree2.resize(N + 1);
      }
      tree = convolve(tree, MSet(chain1)); tree.resize(N + 1);
    }
    
    for (int k = 1; k <= N; ++k) {
      if (k > 1) printf(" ");
      printf("%u", ans[k].x);
    }
    puts("");
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3960kb

input:

3 100000007

output:

1 0 0

result:

ok 3 number(s): "1 0 0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4228kb

input:

6 300000007

output:

1 5 0 0 0 0

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

10 1000000007

output:

1 104 1 0 0 0 0 0 0 0

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 4260kb

input:

2 739878731

output:

1 0

result:

ok 2 number(s): "1 0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

3 122646779

output:

1 0 0

result:

ok 3 number(s): "1 0 0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 4232kb

input:

4 457287433

output:

1 1 0 0

result:

ok 4 number(s): "1 1 0 0"

Test #7:

score: 0
Accepted
time: 0ms
memory: 4264kb

input:

5 1000000007

output:

1 2 0 0 0

result:

ok 5 number(s): "1 2 0 0 0"

Test #8:

score: 0
Accepted
time: 0ms
memory: 4268kb

input:

6 1000000007

output:

1 5 0 0 0 0

result:

ok 6 numbers

Test #9:

score: 0
Accepted
time: 1ms
memory: 3960kb

input:

7 763596907

output:

1 10 0 0 0 0 0

result:

ok 7 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 4256kb

input:

8 1000000007

output:

1 22 0 0 0 0 0 0

result:

ok 8 numbers

Test #11:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

9 729507523

output:

1 46 0 0 0 0 0 0 0

result:

ok 9 numbers

Test #12:

score: 0
Accepted
time: 1ms
memory: 3964kb

input:

11 488473873

output:

1 230 4 0 0 0 0 0 0 0 0

result:

ok 11 numbers

Test #13:

score: 0
Accepted
time: 1ms
memory: 3988kb

input:

12 100000007

output:

1 531 19 0 0 0 0 0 0 0 0 0

result:

ok 12 numbers

Test #14:

score: 0
Accepted
time: 1ms
memory: 3972kb

input:

13 1000000007

output:

1 1223 77 0 0 0 0 0 0 0 0 0 0

result:

ok 13 numbers

Test #15:

score: 0
Accepted
time: 1ms
memory: 4232kb

input:

14 1000000007

output:

1 2871 287 0 0 0 0 0 0 0 0 0 0 0

result:

ok 14 numbers

Test #16:

score: 0
Accepted
time: 1ms
memory: 4272kb

input:

15 290707159

output:

1 6738 1002 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 15 numbers

Test #17:

score: 0
Accepted
time: 1ms
memory: 4264kb

input:

16 200746561

output:

1 15954 3365 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 16 numbers

Test #18:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

17 920695687

output:

1 37775 10853 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 17 numbers

Test #19:

score: 0
Accepted
time: 1ms
memory: 4044kb

input:

18 100000007

output:

1 89778 34088 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 18 numbers

Test #20:

score: 0
Accepted
time: 1ms
memory: 4264kb

input:

19 1000000007

output:

1 213380 104574 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 19 numbers

Test #21:

score: 0
Accepted
time: 1ms
memory: 4048kb

input:

20 1000000007

output:

1 507948 315116 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 20 numbers

Test #22:

score: 0
Accepted
time: 1ms
memory: 4036kb

input:

21 1000000007

output:

1 1209183 935321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 21 numbers

Test #23:

score: 0
Accepted
time: 1ms
memory: 3980kb

input:

22 293085943

output:

1 2880381 2743373 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 22 numbers

Test #24:

score: 0
Accepted
time: 1ms
memory: 4272kb

input:

23 1000000007

output:

1 6861350 7966717 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 23 numbers

Test #25:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

24 1000000007

output:

1 16348886 22950963 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 24 numbers

Test #26:

score: 0
Accepted
time: 1ms
memory: 4048kb

input:

25 100000007

output:

1 38955353 65681223 313 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 25 numbers

Test #27:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

31 534112939

output:

1 192268405 73638402 6451797 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 31 numbers

Test #28:

score: 0
Accepted
time: 1ms
memory: 4012kb

input:

32 1000000007

output:

1 5929365 938116336 28363756 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 32 numbers

Test #29:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

33 100000007

output:

1 28626901 79818017 20396526 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 33 numbers

Test #30:

score: 0
Accepted
time: 1ms
memory: 3996kb

input:

45 449530979

output:

1 171137267 404676218 400336656 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 45 numbers

Test #31:

score: 0
Accepted
time: 1ms
memory: 4036kb

input:

46 1000000007

output:

1 199174750 533156646 230095585 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 46 numbers

Test #32:

score: 0
Accepted
time: 2ms
memory: 3976kb

input:

63 901518881

output:

1 463582236 485174050 287704421 146635752 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 63 numbers

Test #33:

score: 0
Accepted
time: 2ms
memory: 3976kb

input:

64 137267147

output:

1 35160421 46570987 16058722 84291291 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 64 numbers

Test #34:

score: 0
Accepted
time: 2ms
memory: 4272kb

input:

65 285342521

output:

1 274680000 185520281 272194478 194410283 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 65 numbers

Test #35:

score: 0
Accepted
time: 3ms
memory: 4288kb

input:

93 927588749

output:

1 739012354 414231470 524375705 491769836 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 93 numbers

Test #36:

score: 0
Accepted
time: 3ms
memory: 3984kb

input:

94 1000000007

output:

1 174061321 12227912 673546067 414725694 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 94 numbers

Test #37:

score: 0
Accepted
time: 3ms
memory: 3968kb

input:

127 837565763

output:

1 446351899 736480797 801225275 81764442 837167518 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 127 numbers

Test #38:

score: 0
Accepted
time: 5ms
memory: 4292kb

input:

128 100000007

output:

1 53744379 39517387 95806759 76712174 64599518 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 128 numbers

Test #39:

score: 0
Accepted
time: 5ms
memory: 4292kb

input:

129 100000007

output:

1 54413572 77155852 35776158 8059026 50094475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

ok 129 numbers

Test #40:

score: 0
Accepted
time: 6ms
memory: 4012kb

input:

189 100000007

output:

1 20631572 98966220 97206167 20535001 98542068 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 189 numbers

Test #41:

score: 0
Accepted
time: 6ms
memory: 4016kb

input:

190 1000000007

output:

1 860182239 85061792 915947137 663567155 838976700 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 190 numbers

Test #42:

score: 0
Accepted
time: 7ms
memory: 4036kb

input:

251 100000007

output:

1 44059658 9262465 26500589 1719804 86005028 93059166 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 251 numbers

Test #43:

score: 0
Accepted
time: 5ms
memory: 3992kb

input:

252 438884497

output:

1 350004178 339722925 331392720 339369500 346888489 145616211 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 252 numbers

Test #44:

score: 0
Accepted
time: 3ms
memory: 4052kb

input:

253 603030559

output:

1 271460264 113828285 211485995 140494699 117148110 528164491 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 253 numbers

Test #45:

score: 0
Accepted
time: 6ms
memory: 4016kb

input:

254 348935141

output:

1 43492722 336540922 302203252 295334615 232628368 334090063 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 254 numbers

Test #46:

score: 0
Accepted
time: 7ms
memory: 4016kb

input:

255 1000000007

output:

1 91921129 240703773 860507313 874767125 217480414 312302154 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 255 numbers

Test #47:

score: 0
Accepted
time: 7ms
memory: 4324kb

input:

256 1000000007

output:

1 53171383 308195745 292391229 411819088 716198819 576070511 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 256 numbers

Test #48:

score: 0
Accepted
time: 11ms
memory: 4064kb

input:

257 100000007

output:

1 81139239 17341218 77559815 79820516 8464002 98148398 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 257 numbers

Test #49:

score: 0
Accepted
time: 11ms
memory: 4320kb

input:

258 442383839

output:

1 17124647 269217418 150135508 44573661 331788565 178732642 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 258 numbers

Test #50:

score: 0
Accepted
time: 11ms
memory: 4112kb

input:

259 1000000007

output:

1 110221852 366165150 234264934 260805622 864063783 707330112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 259 numbers

Test #51:

score: 0
Accepted
time: 11ms
memory: 4044kb

input:

260 712345379

output:

1 695448021 314265267 409389839 186491237 137959338 602047939 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 260 numbers

Test #52:

score: 0
Accepted
time: 11ms
memory: 4028kb

input:

261 905487833

output:

1 343672449 301480800 74963931 846427040 50121928 66712132 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 261 numbers

Test #53:

score: 0
Accepted
time: 13ms
memory: 4044kb

input:

379 785307437

output:

1 104449237 551856852 287086915 700424952 260302548 683038837 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 379 numbers

Test #54:

score: 0
Accepted
time: 14ms
memory: 4020kb

input:

380 1000000007

output:

1 898776986 792687672 458428823 424922724 540625189 703369531 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 380 numbers

Test #55:

score: 0
Accepted
time: 13ms
memory: 4048kb

input:

381 1000000007

output:

1 792757940 914747475 138265905 619378463 243945373 245237150 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 381 numbers

Test #56:

score: 0
Accepted
time: 15ms
memory: 4052kb

input:

382 1000000007

output:

1 967586300 862777957 762030482 699420239 261107449 927966095 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 382 numbers

Test #57:

score: 0
Accepted
time: 15ms
memory: 4048kb

input:

383 215369873

output:

1 137773847 215004848 201659396 179799367 6430943 40328459 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 383 numbers

Test #58:

score: 0
Accepted
time: 15ms
memory: 4044kb

input:

384 1000000007

output:

1 507910674 458483513 431720627 483110084 435044603 540855576 369 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 384 numbers

Test #59:

score: 0
Accepted
time: 15ms
memory: 4044kb

input:

385 454793887

output:

1 248403036 291298368 251944296 296123869 371504911 24661638 8879 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 385 numbers

Test #60:

score: 0
Accepted
time: 15ms
memory: 4124kb

input:

386 1000000007

output:

1 265750215 79378345 232928900 483946141 205160466 429741317 202552 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 386 numbers

Test #61:

score: 0
Accepted
time: 15ms
memory: 4084kb

input:

387 227519269

output:

1 10763873 128932761 4923580 111935720 101016988 55107358 4366847 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 387 numbers

Test #62:

score: 0
Accepted
time: 15ms
memory: 4044kb

input:

388 1000000007

output:

1 958804227 524180264 304133528 240757407 115032333 782719263 89834392 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 388 numbers

Test #63:

score: 0
Accepted
time: 13ms
memory: 4112kb

input:

389 100000007

output:

1 1930815 57848302 3602158 77887435 14525348 1062339 70400721 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 389 numbers

Test #64:

score: 0
Accepted
time: 17ms
memory: 4036kb

input:

490 100000007

output:

1 96342386 17439556 23314154 89355902 37007860 13022516 15758638 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 490 numbers

Test #65:

score: 0
Accepted
time: 17ms
memory: 4060kb

input:

491 150073523

output:

1 9711255 122670986 90390709 18503883 27665285 140185636 116277727 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 491 numbers

Test #66:

score: 0
Accepted
time: 13ms
memory: 4008kb

input:

492 100000007

output:

1 53440278 34811222 65887674 39632523 80352836 51887989 53638950 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 492 numbers

Test #67:

score: 0
Accepted
time: 18ms
memory: 4060kb

input:

493 1000000007

output:

1 744781325 335559402 899766846 495308909 483295651 260407300 970927089 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 493 numbers

Test #68:

score: 0
Accepted
time: 17ms
memory: 4060kb

input:

494 267940807

output:

1 173520076 91930068 196027436 182150385 254288786 233046355 184330491 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 494 numbers

Test #69:

score: 0
Accepted
time: 17ms
memory: 4064kb

input:

495 103825471

output:

1 103727223 64685514 91375652 39482044 46185280 83105809 50113222 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 495 numbers

Test #70:

score: 0
Accepted
time: 17ms
memory: 4072kb

input:

496 849169157

output:

1 344999439 495436786 781457946 404504956 270903993 494266348 209361467 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 496 numbers

Test #71:

score: 0
Accepted
time: 17ms
memory: 4348kb

input:

497 662520673

output:

1 156500838 639965771 190377618 568425495 81997 303944968 210618835 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 497 numbers

Test #72:

score: 0
Accepted
time: 18ms
memory: 4124kb

input:

498 1000000007

output:

1 573703418 935865068 977863365 602392352 835769495 352753836 613593614 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 498 numbers

Test #73:

score: 0
Accepted
time: 17ms
memory: 4328kb

input:

499 197518697

output:

1 183648021 12587187 141992294 103512133 121413153 142956322 51677789 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 499 numbers

Test #74:

score: 0
Accepted
time: 14ms
memory: 4076kb

input:

500 351956881

output:

1 278454371 270002440 87590952 340114688 136937620 87109359 224401059 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 500 numbers

Extra Test:

score: 0
Extra Test Passed