結果
問題 | No.2211 Frequency Table of GCD |
ユーザー | tsugutsugu |
提出日時 | 2023-03-05 13:20:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 2,720 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 171,568 KB |
実行使用メモリ | 18,176 KB |
最終ジャッジ日時 | 2024-09-18 01:34:02 |
合計ジャッジ時間 | 3,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
15,616 KB |
testcase_01 | AC | 6 ms
15,616 KB |
testcase_02 | AC | 6 ms
15,616 KB |
testcase_03 | AC | 23 ms
17,024 KB |
testcase_04 | AC | 31 ms
17,152 KB |
testcase_05 | AC | 37 ms
17,424 KB |
testcase_06 | AC | 30 ms
17,152 KB |
testcase_07 | AC | 41 ms
17,664 KB |
testcase_08 | AC | 11 ms
16,000 KB |
testcase_09 | AC | 10 ms
15,884 KB |
testcase_10 | AC | 17 ms
16,384 KB |
testcase_11 | AC | 15 ms
16,256 KB |
testcase_12 | AC | 17 ms
16,384 KB |
testcase_13 | AC | 28 ms
17,024 KB |
testcase_14 | AC | 32 ms
17,420 KB |
testcase_15 | AC | 27 ms
17,152 KB |
testcase_16 | AC | 30 ms
17,280 KB |
testcase_17 | AC | 37 ms
17,408 KB |
testcase_18 | AC | 48 ms
18,176 KB |
testcase_19 | AC | 49 ms
18,048 KB |
testcase_20 | AC | 50 ms
17,920 KB |
testcase_21 | AC | 50 ms
17,920 KB |
testcase_22 | AC | 51 ms
17,920 KB |
testcase_23 | AC | 25 ms
17,280 KB |
testcase_24 | AC | 43 ms
17,920 KB |
testcase_25 | AC | 19 ms
16,512 KB |
testcase_26 | AC | 7 ms
15,616 KB |
testcase_27 | AC | 47 ms
17,920 KB |
testcase_28 | AC | 42 ms
17,932 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500044; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; const int mxM = 2e5 + 2; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> cnt(mxM, 0); for (int i = 0; i < n; i++) { cnt[a[i]]++; } vector<Mint> ans(m + 1, 0); for (int i = m; i >= 1; i--) { int cur = 0; for (int j = i; j < mxM; j += i) { cur += cnt[j]; } ans[i] = Mint(2).pow(cur) - 1; for (int j = i + i; j <= m; j += i) { ans[i] -= ans[j]; } } for (int i = 1; i <= m; i++) { cout << ans[i] << '\n'; } }