結果

問題 No.2211 Frequency Table of GCD
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-05 07:15:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 109,012 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-02 06:39:39
合計ジャッジ時間 9,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 256 ms
7,552 KB
testcase_04 AC 215 ms
6,272 KB
testcase_05 AC 262 ms
6,912 KB
testcase_06 AC 259 ms
7,040 KB
testcase_07 AC 310 ms
7,680 KB
testcase_08 AC 15 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 28 ms
5,376 KB
testcase_11 AC 21 ms
5,376 KB
testcase_12 AC 31 ms
5,376 KB
testcase_13 AC 209 ms
6,272 KB
testcase_14 AC 283 ms
7,552 KB
testcase_15 AC 252 ms
7,296 KB
testcase_16 AC 266 ms
7,424 KB
testcase_17 AC 255 ms
6,912 KB
testcase_18 AC 340 ms
8,064 KB
testcase_19 AC 346 ms
7,936 KB
testcase_20 AC 353 ms
8,064 KB
testcase_21 AC 350 ms
8,064 KB
testcase_22 AC 362 ms
8,064 KB
testcase_23 AC 278 ms
7,936 KB
testcase_24 AC 341 ms
7,936 KB
testcase_25 AC 30 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 336 ms
7,936 KB
testcase_28 AC 340 ms
8,064 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;
using ll = long long;

const ll modc = 998244353;

long long mod_exp(long long b, long long e, long long m){
    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(){

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

    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--){
        dp[i] = mod_exp(2, cnt[i], modc) - 1;
        for (int j=2*i; j<=M; j+=i){
            dp[i] += (modc - dp[j]);
            dp[i] %= modc;
        }
    }

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

    return 0;
}
0