結果

問題 No.2211 Frequency Table of GCD
ユーザー siman
提出日時 2023-02-13 17:24:01
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 141,788 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-16 11:18:18
合計ジャッジ時間 9,375 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll mod_pow(ll x, ll n, ll mod = MOD) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }

    x = x * x % mod;
    n >>= 1;
  }

  return res;
}

int main() {
  int N, M;
  cin >> N >> M;

  int counter[M + 1];
  memset(counter, 0, sizeof(counter));

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    ++counter[A[i]];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  vector<ll> ans(M + 1, 0);

  for (int a = M; a >= 1; --a) {
    ll cnt = 0;

    int v = a;
    while (v <= M) {
      cnt += counter[v];
      v += a;
    }

    ll c = (mod_pow(2, cnt) - 1 + MOD) % MOD;
    v = 2 * a;
    while (v <= M) {
      c -= ans[v];
      c = (c + MOD) % MOD;
      v += a;
    }

    ans[a] = c;
  }

  for (int m = 1; m <= M; ++m) {
    cout << ans[m] << endl;
  }

  return 0;
}
0