#line 1 "a.cpp" #include using namespace std; using ll=long long; using ld=long double; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} #include using mint = atcoder::modint998244353; #line 3 "/Users/Shared/po167_library/fps/FPS_inv.hpp" #include namespace po167{ // return 1 / f template std::vector FPS_inv(std::vector f, int len = -1){ if (len == -1) len = f.size(); assert(f[0] != 0); std::vector g = {1 / f[0]}; int s = 1; while(s < len){ // g = 2g_s - f(g_s)^2 (mod x ^ (2 * s)) // g = g - (fg - 1)g // (fg - 1) = 0 (mod x ^ (s)) std::vector n_g(s * 2, 0); std::vector f_s(s * 2, 0); g.resize(s * 2); for (int i = 0; i < s * 2; i++){ if (int(f.size()) > i) f_s[i] = f[i]; n_g[i] = g[i]; } atcoder::internal::butterfly(g); atcoder::internal::butterfly(f_s); for (int i = 0; i < s * 2; i++){ f_s[i] *= g[i]; } atcoder::internal::butterfly_inv(f_s); T iz = 1 / (T)(s * 2); for (int i = s; i < s * 2; i++){ f_s[i] *= iz; } for (int i = 0; i < s; i++){ f_s[i] = 0; } atcoder::internal::butterfly(f_s); for (int i = 0; i < s * 2; i++){ f_s[i] *= g[i]; } atcoder::internal::butterfly_inv(f_s); for (int i = s; i < s * 2; i++){ n_g[i] -= f_s[i] * iz; } std::swap(n_g, g); s *= 2; } g.resize(len); return g; } } #line 2 "/Users/Shared/po167_library/math/Binomial.hpp" #line 5 "/Users/Shared/po167_library/math/Binomial.hpp" namespace po167{ template struct Binomial{ std::vector fact_vec, fact_inv_vec; void extend(int m = -1){ int n = fact_vec.size(); if (m == -1) m = n * 2; if (n >= m) return; fact_vec.resize(m); fact_inv_vec.resize(m); for (int i = n; i < m; i++){ fact_vec[i] = fact_vec[i - 1] * T(i); } fact_inv_vec[m - 1] = T(1) / fact_vec[m - 1]; for (int i = m - 1; i > n; i--){ fact_inv_vec[i - 1] = fact_inv_vec[i] * T(i); } } Binomial(int MAX = 0){ fact_vec.resize(1, T(1)); fact_inv_vec.resize(1, T(1)); extend(MAX + 1); } T fact(int i){ if (i < 0) return 0; while (int(fact_vec.size()) <= i) extend(); return fact_vec[i]; } T invfact(int i){ if (i < 0) return 0; while (int(fact_inv_vec.size()) <= i) extend(); return fact_inv_vec[i]; } T C(int a, int b){ if (a < b || b < 0) return 0; return fact(a) * invfact(b) * invfact(a - b); } T invC(int a, int b){ if (a < b || b < 0) return 0; return fact(b) * fact(a - b) *invfact(a); } T P(int a, int b){ if (a < b || b < 0) return 0; return fact(a) * invfact(a - b); } T inv(int a){ if (a < 0) return inv(-a) * T(-1); if (a == 0) return 1; return fact(a - 1) * invfact(a); } T Catalan(int n){ if (n < 0) return 0; return fact(2 * n) * invfact(n + 1) * invfact(n); } T narayana(int n, int k){ if (n <= 0 || n < k || k < 1) return 0; return C(n, k) * C(n, k - 1) * inv(n); } T Catalan_pow(int n,int d){ if (n < 0 || d < 0) return 0; if (d == 0){ if (n == 0) return 1; return 0; } return T(d) * inv(d + n) * C(2 * n + d - 1, n); } // retrun [x^a] 1/(1-x)^b T ruiseki(int a,int b){ if (a < 0 || b < 0) return 0; if (a == 0){ return 1; } return C(a + b - 1, b - 1); } // (a, b) -> (c, d) // always x + e >= y T mirror(int a, int b, int c, int d, int e = 0){ if (a + e < b || c + e < d) return 0; if (a > c || b > d) return 0; a += e; c += e; return C(c + d - a - b, c - a) - C(c + d - a - b, c - b + 1); } // return sum_{i = 0, ... , a} sum_{j = 0, ... , b} C(i + j, i) // return C(a + b + 2, a + 1) - 1; T gird_sum(int a, int b){ if (a < 0 || b < 0) return 0; return C(a + b + 2, a + 1) - 1; } // return sum_{i = a, ..., b - 1} sum_{j = c, ... , d - 1} C(i + j, i) // AGC 018 E T gird_sum_2(int a, int b, int c, int d){ if (a >= b || c >= d) return 0; a--, b--, c--, d--; return gird_sum(a, c) - gird_sum(a, d) - gird_sum(b, c) + gird_sum(b, d); } }; } #line 3 "/Users/Shared/po167_library/fps/FPS_differetial.hpp" namespace po167{ // return f' template std::vector FPS_differential(std::vector f){ if (f.empty()) return f; for (int i = 0; i < (int)f.size() - 1; i++){ f[i] = f[i + 1] * (T)(i + 1); } f.pop_back(); return f; } } #line 3 "/Users/Shared/po167_library/fps/FPS_integral.hpp" namespace po167{ template std::vector FPS_integral(std::vector f){ if (f.empty()) return f; std::vector num_inv((int)f.size() + 1); num_inv[0] = 1; num_inv[1] = 1; auto m = T::mod(); for (int i = 2; i <= (int)f.size(); i++){ num_inv[i] = (0 - num_inv[m % i]) * (T)(m / i); } f.reserve((int)f.size() + 1); f.push_back(0); for (int i = (int)f.size() - 1; i > 0; i--){ f[i] = f[i - 1] * num_inv[i]; } f[0] = 0; return f; } } #line 5 "/Users/Shared/po167_library/fps/FPS_log.hpp" namespace po167{ template std::vector FPS_log(std::vector f, int len = -1){ if (len == -1) len = f.size(); if (len == 0) return {}; if (len == 1) return {T(0)}; assert(!f.empty() && f[0] == 1); std::vector res = atcoder::convolution(FPS_differential(f), FPS_inv(f, len)); res.resize(len - 1); return FPS_integral(res); } } #line 4 "/Users/Shared/po167_library/fps/FPS_cyclic_convolution.hpp" namespace po167{ // |f| = |g| = 2 ^ n template std::vector FPS_cyclic_convolution(std::vector f, std::vector g){ atcoder::internal::butterfly(f); atcoder::internal::butterfly(g); for (int i = 0; i < (int)f.size(); i++) f[i] *= g[i]; atcoder::internal::butterfly_inv(f); T iz = (T)(1) / (T)(f.size()); for (int i = 0; i < (int)f.size(); i++) f[i] *= iz; return f; } } #line 8 "/Users/Shared/po167_library/fps/FPS_exp.hpp" namespace po167{ template std::vector FPS_exp(std::vector f, int len = -1){ if (len == -1) len = f.size(); if (len == 0) return {}; if (len == 1) return {T(1)}; assert(!f.empty() && f[0] == 0); int s = 1; // simple std::vector g = {T(1)}; while (s < len){ // g' / g // A * B std::vector A = g, B = g; A = FPS_differential(A); B = FPS_inv(B, 2 * s); A.resize(2 * s); A = FPS_cyclic_convolution(A, B); A.pop_back(); A = FPS_integral(A); for (int i = 0; i < s; i++) A[i] = 0; for (int i = s; i < s * 2; i++) A[i] = (i < (int)f.size() ? f[i] : 0) - A[i]; // g_hat = g (1 - g + f) // g += B = g * A g.resize(2 * s); B = FPS_cyclic_convolution(A, g); for (int i = s; i < s * 2; i++) g[i] = B[i]; s *= 2; } g.resize(len); return g; } } #line 31 "a.cpp" void solve(); // CYAN / FREDERIC int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ int N, K; cin >> N >> K; vector C(K + 1); rep(i, 0, K){ C[gcd(i, K)] += 1; } vector A(N); rep(i, 0, N) cin >> A[i]; mint ans = 0; po167::Binomial table; vector base(K + 1, vector(K + 1)); base[0][0] = 1; rep(i, 1, K + 1){ base[i] = base[i - 1]; base[i][i] = table.invfact(i); } rep(i, 0, K + 1) base[i] = po167::FPS_log(base[i]); vector B(K + 2); rep(i, 0, N) B[min(K, A[i]) + 1]++; rep(i, 0, K + 1) B[i + 1] += B[i]; rep(len, 0, K + 1) if (C[len].val() != 0){ vector dp(len + 1); int inv = K / len; rep(i, 0, len + 1){ int tmp; if (i != len){ tmp = B[(i + 1) * inv] - B[i * inv]; } else{ tmp = B[K + 1] - B[K]; } if (tmp != 0){ rep(j, 0, len + 1) dp[j] += base[i][j] * tmp; } } dp = po167::FPS_exp(dp); ans += dp.back() * table.fact(len) * C[len]; } ans /= K; cout << ans.val() << "\n"; }