結果

問題 No.2211 Frequency Table of GCD
ユーザー simansiman
提出日時 2023-02-13 17:13:45
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,107 bytes
コンパイル時間 6,269 ms
コンパイル使用メモリ 107,692 KB
実行使用メモリ 6,412 KB
最終ジャッジ日時 2023-09-23 11:39:02
合計ジャッジ時間 10,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 255 ms
5,604 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 998244355;

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 : 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