#include #include #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; } #define COLOR(s) ("\x1b[" s "m") //////////////////////////////////////////////////////////////////////////////// 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; } }; //////////////////////////////////////////////////////////////////////////////// constexpr unsigned MO = 998244353; using Mint = ModInt; template vector merge(const vector &a, const vector &b) { vector c(a.size() + b.size()); std::merge(a.begin(), a.end(), b.begin(), b.end(), c.begin()); return c; } template T power(T a, Int e, T m) { T b = 1; for (; e; e >>= 1) { if (e & 1) b = (b * a) % m; a = (a * a) % m; } return b; } Int gcd(Int a, Int b) { if (a < 0) a = -a; if (b < 0) b = -b; if (a == 0) return b; if (b == 0) return a; const int s = __builtin_ctzll(a | b); a >>= __builtin_ctzll(a); do { b >>= __builtin_ctzll(b); if (a > b) std::swap(a, b); b -= a; } while (b); return a << s; } // Checks if n is a prime using Miller-Rabin test bool isPrime(Int n) { if (n <= 1 || n % 2 == 0) return (n == 2); const int s = __builtin_ctzll(n - 1); const Int d = (n - 1) >> s; // http://miller-rabin.appspot.com/ for (const Int base : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { __int128 a = base % n; if (a == 0) continue; a = power<__int128>(a, d, n); if (a == 1 || a == n - 1) continue; bool ok = false; for (int i = 0; i < s - 1; ++i) { a = (a * a) % n; if (a == n - 1) { ok = true; break; } } if (!ok) return false; } return true; } // Factorize n using Pollard's rho algorithm vector factorize(Int n) { static constexpr int BLOCK = 256; if (n <= 1) return {}; if (isPrime(n)) return {n}; if (n % 2 == 0) return merge({2}, factorize(n / 2)); for (Int c = 2; ; ++c) { Int x, y = 2, y0, z = 1, d = 1; for (int l = 1; d == 1; l <<= 1) { x = y; for (int i = 0; i < l; ++i) y = (static_cast<__int128>(y) * y + c) % n; for (int i = 0; i < l; i += BLOCK) { y0 = y; for (int j = 0; j < BLOCK && j < l - i; ++j) { y = (static_cast<__int128>(y) * y + c) % n; z = (static_cast<__int128>(z) * (y - x)) % n; } if ((d = gcd(z, n)) != 1) break; } } if (d == n) { for (y = y0; ; ) { y = (static_cast<__int128>(y) * y + c) % n; if ((d = gcd(y - x, n)) != 1) break; } } if (d != n) return merge(factorize(d), factorize(n / d)); } } int T; Int M; int N; Mint B, C, D; vector A; int main() { for (; ~scanf("%d%lld", &T, &M); ) { vector ps; vector es; { const auto res = factorize(M); for (int i = 0, j = 0; i < (int)res.size(); ++i) { for (; j < (int)res.size() && res[i] == res[j]; ++j) {} ps.push_back(res[i]); es.push_back(j - i); } } const int len = ps.size(); // cerr<<"ps = "< fs(1 << len, 1); Mint w = B; for (int i = 0; i < N; ++i) { if (M % A[i] == 0) { int h = 0; for (int k = 0; k < len; ++k) { int e = 0; for (Int a = A[i]; a % ps[k] == 0; a /= ps[k]) ++e; if (e < es[k]) { h |= 1 << k; } } fs[h] *= (1 + w); } w = C * w + D; } // cerr<<"fs = "<