結果

問題 No.2211 Frequency Table of GCD
ユーザー Today03
提出日時 2024-11-05 10:15:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 2,606 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 253,280 KB
実行使用メモリ 27,852 KB
最終ジャッジ日時 2024-11-05 10:15:57
合計ジャッジ時間 11,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

template <ll MOD>
struct ModInt {
    ll value;
    ModInt(ll x = 0) { value = (x >= 0 ? x % MOD : MOD - (-x) % MOD); }
    ModInt operator-() const { return ModInt(-value); }
    ModInt operator+() const { return ModInt(*this); }
    ModInt& operator+=(const ModInt& other) {
        value += other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& other) {
        value += MOD - other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt other) {
        value = value * other.value % MOD;
        return *this;
    }
    ModInt& operator/=(ModInt other) {
        (*this) *= other.inv();
        return *this;
    }
    ModInt operator+(const ModInt& other) const { return ModInt(*this) += other; }
    ModInt operator-(const ModInt& other) const { return ModInt(*this) -= other; }
    ModInt operator*(const ModInt& other) const { return ModInt(*this) *= other; }
    ModInt operator/(const ModInt& other) const { return ModInt(*this) /= other; }
    ModInt pow(ll x) const {
        ModInt ret(1), mul(value);
        while (x) {
            if (x & 1) ret *= mul;
            mul *= mul;
            x >>= 1;
        }
        return ret;
    }
    ModInt inv() const { return pow(MOD - 2); }
    bool operator==(const ModInt& other) const { return value == other.value; }
    bool operator!=(const ModInt& other) const { return value != other.value; }
    friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; }
    friend istream& operator>>(istream& is, ModInt& x) {
        ll v;
        is >> v;
        x = ModInt<MOD>(v);
        return is;
    }
    static constexpr ll get_mod() { return MOD; }
};
using Mod998 = ModInt<998244353>;
using Mod107 = ModInt<1000000007>;

using mint = Mod998;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<vector<int>> div(M + 1);
    for (int i = 1; i <= M; i++) {
        for (int j = i; j <= M; j += i) {
            div[j].push_back(i);
        }
    }
    vector<int> ex(M + 1);
    for (int i = 0; i < N; i++) {
        for (int x : div[A[i]]) ex[x]++;
    }

    vector<mint> dp(M + 1);
    for (int i = M; i >= 1; i--) {
        dp[i] = mint(2).pow(ex[i]) - 1;
        for (int j = i * 2; j <= M; j += i) {
            dp[i] -= dp[j];
        }
    }

    for (int i = 1; i <= M; i++) cout << dp[i] << '\n';
}
0