結果

問題 No.2211 Frequency Table of GCD
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-02-11 02:29:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 108,152 KB
実行使用メモリ 9,408 KB
最終ジャッジ日時 2023-09-22 02:34:42
合計ジャッジ時間 8,955 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 247 ms
7,216 KB
testcase_04 AC 212 ms
6,800 KB
testcase_05 AC 257 ms
7,708 KB
testcase_06 AC 252 ms
7,440 KB
testcase_07 AC 301 ms
8,432 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 28 ms
4,504 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 30 ms
4,376 KB
testcase_13 AC 200 ms
6,784 KB
testcase_14 AC 282 ms
7,704 KB
testcase_15 AC 250 ms
7,140 KB
testcase_16 AC 267 ms
7,588 KB
testcase_17 AC 249 ms
7,412 KB
testcase_18 AC 349 ms
9,340 KB
testcase_19 AC 345 ms
9,320 KB
testcase_20 AC 347 ms
9,364 KB
testcase_21 AC 342 ms
9,324 KB
testcase_22 AC 344 ms
9,392 KB
testcase_23 AC 276 ms
7,780 KB
testcase_24 AC 332 ms
9,332 KB
testcase_25 AC 30 ms
4,876 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 336 ms
9,408 KB
testcase_28 AC 331 ms
9,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

const long long modc = 998244353;

long long mod_exp(long long b, long long e){
    const long long m=modc;
    if (e > 0 && b == 0) return 0;
    long long ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){

    long long N, M;
    cin >> N >> M;
    vector<long long> A(N), c(M+1), cnt(M+1), ans(M+1);
    for (int i=0; i<N; i++){
        cin >> A[i];
        c[A[i]]++;
    }

    for (int i=1; i<=M; i++){
        for (int j=i; j<=M; j+=i) cnt[i] += c[j];
    }

    for (int i=M; i>=1; i--){
        ans[i] = (modc+mod_exp(2, cnt[i])-1) % modc;
        for (int j=2*i; j<=M; j+=i){
            ans[i] += modc - ans[j];
            ans[i] %= modc;
        }
    }

    for (int i=1; i<=M; i++) cout << ans[i] << endl;

    return 0;
}
0