結果
問題 | No.2211 Frequency Table of GCD |
ユーザー | ineedyourlovep |
提出日時 | 2023-02-10 22:04:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 802 ms / 2,000 ms |
コード長 | 3,440 bytes |
コンパイル時間 | 4,958 ms |
コンパイル使用メモリ | 218,832 KB |
実行使用メモリ | 21,088 KB |
最終ジャッジ日時 | 2023-09-22 01:08:40 |
合計ジャッジ時間 | 13,726 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
6,552 KB |
testcase_01 | AC | 19 ms
6,772 KB |
testcase_02 | AC | 18 ms
6,488 KB |
testcase_03 | AC | 82 ms
18,500 KB |
testcase_04 | AC | 334 ms
15,716 KB |
testcase_05 | AC | 539 ms
17,532 KB |
testcase_06 | AC | 298 ms
17,644 KB |
testcase_07 | AC | 516 ms
19,656 KB |
testcase_08 | AC | 47 ms
7,080 KB |
testcase_09 | AC | 39 ms
6,964 KB |
testcase_10 | AC | 81 ms
7,744 KB |
testcase_11 | AC | 61 ms
7,468 KB |
testcase_12 | AC | 89 ms
7,800 KB |
testcase_13 | AC | 280 ms
15,408 KB |
testcase_14 | AC | 277 ms
19,164 KB |
testcase_15 | AC | 188 ms
17,940 KB |
testcase_16 | AC | 258 ms
18,648 KB |
testcase_17 | AC | 478 ms
17,328 KB |
testcase_18 | AC | 802 ms
21,044 KB |
testcase_19 | AC | 784 ms
21,016 KB |
testcase_20 | AC | 774 ms
21,032 KB |
testcase_21 | AC | 784 ms
20,972 KB |
testcase_22 | AC | 792 ms
21,088 KB |
testcase_23 | AC | 95 ms
19,524 KB |
testcase_24 | AC | 320 ms
20,976 KB |
testcase_25 | AC | 52 ms
8,112 KB |
testcase_26 | AC | 19 ms
6,604 KB |
testcase_27 | AC | 531 ms
21,088 KB |
testcase_28 | AC | 319 ms
21,080 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; //const int mod = 1000000007; const int mod = 998244353; //MINT struct mint { unsigned x; mint(): x(0) {} mint(ll x):x((x%mod+mod)%mod) {} mint operator-() const { return mint(0) - *this;} mint operator~() const { return mint(1) / *this;} mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;} mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;} mint& operator*=(const mint& a) { x=(unsigned long long)x*a.x%mod; return *this;} mint& operator/=(const mint& a) { x=(unsigned long long)x*a.pow(mod-2).x%mod; return *this;} mint operator+(const mint& a) const { return mint(*this) += a;} mint operator-(const mint& a) const { return mint(*this) -= a;} mint operator*(const mint& a) const { return mint(*this) *= a;} mint operator/(const mint& a) const { return mint(*this) /= a;} mint pow(ll t) const { if (!t) return 1; mint res = pow(t>>1); res *= res; return (t&1)?res*x:res; } bool operator<(const mint& a) const { return x < a.x;} bool operator==(const mint& a) const { return x == a.x;} bool operator!=(const mint& a) const { return x != a.x;} }; mint ex(mint x, ll t) { return x.pow(t);} istream& operator>>(istream& i, mint& a) { unsigned long long t; i>>t; a=mint(t); return i;} ostream& operator<<(ostream& o, const mint& a) { return o<<a.x;} //Eratosthenes template<typename T> struct Eratosthenes{ vector<bool> isprime; vector<T> sieves; vector<T> minfactor; vector<T> mobius; Eratosthenes(T n=0):isprime(n+1, true), minfactor(n+1, -1), mobius(n+1, 1){ isprime[1] = false; minfactor[1] = 1; for(T i = 2; i <= n; i++){ if(!isprime[i]) continue; minfactor[i] = i; mobius[i] = -1; for(T j = i*2; j <= n; j += i){ isprime[j] = false; if(minfactor[j] == -1) minfactor[j] = i; if((j/i)%i) mobius[j] = -mobius[j]; else mobius[j] = 0; } } for(T i = 2; i <= n; i++) if(isprime[i]) sieves.emplace_back(i); } vector<pair<T, T>> factorize(T n){ vector<pair<T, T>> res; while(n > 1){ int p = minfactor[n]; int exp = 0; while(minfactor[n] == p){ n /= p; exp++; } res.emplace_back(p, exp); } return res; } vector<T> divisors(T n){ vector<T> res({1}); auto pf = factorize(n); for(auto p : pf){ int s = (int)res.size(); for(int i = 0; i < s; i++){ T v = 1; for(int j = 0; j < p.second; j++){ v *= p.first; res.push_back(res[i]*v); } } } return res; } }; // POWER_MODver. N^k % MOD ll mod_pow(ll n, ll k){ ll res = 1; for(; k > 0; k >>= 1){ if(k&1) res = (res*n)%mod; n = (n*n)%mod; } return res; } int main() { ll n, m; cin >> n >> m; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; Eratosthenes<ll> d(200005); map<ll, ll> mp; rep(i, 0, n) { auto div = d.divisors(a[i]); for (auto j : div) { mp[j]++; } } vector<mint> ans(m+1); for (ll i = m; i >= 1; i--) { mint sum = mod_pow(2, mp[i]) - 1; for (ll j = 2*i; j <= m; j += i) { sum -= ans[j]; } ans[i] = sum; } rep(i, 1, m+1) cout << ans[i] << "\n"; return 0; }