結果

問題 No.2211 Frequency Table of GCD
ユーザー Manuel1024Manuel1024
提出日時 2023-02-10 22:46:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 73,732 KB
実行使用メモリ 6,276 KB
最終ジャッジ日時 2023-09-22 01:15:52
合計ジャッジ時間 3,923 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,412 KB
testcase_01 AC 8 ms
5,460 KB
testcase_02 AC 7 ms
5,500 KB
testcase_03 AC 26 ms
5,356 KB
testcase_04 AC 53 ms
5,916 KB
testcase_05 AC 70 ms
6,168 KB
testcase_06 AC 48 ms
5,760 KB
testcase_07 AC 67 ms
5,872 KB
testcase_08 AC 22 ms
5,760 KB
testcase_09 AC 19 ms
5,608 KB
testcase_10 AC 35 ms
6,068 KB
testcase_11 AC 28 ms
5,920 KB
testcase_12 AC 38 ms
5,928 KB
testcase_13 AC 48 ms
5,608 KB
testcase_14 AC 47 ms
5,668 KB
testcase_15 AC 39 ms
5,484 KB
testcase_16 AC 45 ms
5,616 KB
testcase_17 AC 64 ms
5,924 KB
testcase_18 AC 87 ms
6,268 KB
testcase_19 AC 88 ms
6,192 KB
testcase_20 AC 87 ms
6,148 KB
testcase_21 AC 88 ms
6,144 KB
testcase_22 AC 88 ms
6,220 KB
testcase_23 AC 19 ms
5,364 KB
testcase_24 AC 77 ms
6,276 KB
testcase_25 AC 34 ms
6,188 KB
testcase_26 AC 6 ms
5,520 KB
testcase_27 AC 85 ms
6,156 KB
testcase_28 AC 77 ms
6,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;

ll modpow(ll a, ll x){
    ll res = 1;
    for(; x > 0; x >>= 1){
        if(x & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
    }
    return res;
}

int main(){
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    const int lim = 200010;
    vector<int> cnt(lim, 0);
    for(auto &it: a) cnt[it]++;
    vector<ll> f(lim, 0);
    for(int i = lim-10; i > 0; i--){
        int tot = 0;
        for(int j = i; j < lim; j += i) tot += cnt[j];
        if(tot == 0) continue;
        f[i] = (modpow(2, tot)-1+MOD)%MOD;
        for(int j = i+i; j < lim; j += i){
            f[i] -= f[j];
            f[i] += MOD;
            f[i] %= MOD;
        }
    }
    for(int i = 1; i <= m; i++) cout << f[i] << '\n';
    return 0;
}
0