結果

問題 No.2211 Frequency Table of GCD
ユーザー kztasakztasa
提出日時 2023-02-10 22:22:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,963 bytes
コンパイル時間 4,127 ms
コンパイル使用メモリ 237,116 KB
実行使用メモリ 7,108 KB
最終ジャッジ日時 2023-09-21 23:37:37
合計ジャッジ時間 32,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 855 ms
5,192 KB
testcase_04 AC 838 ms
5,528 KB
testcase_05 AC 1,152 ms
6,112 KB
testcase_06 AC 985 ms
5,524 KB
testcase_07 AC 1,336 ms
6,244 KB
testcase_08 AC 27 ms
4,376 KB
testcase_09 AC 21 ms
4,376 KB
testcase_10 AC 60 ms
4,376 KB
testcase_11 AC 41 ms
4,380 KB
testcase_12 AC 66 ms
4,652 KB
testcase_13 AC 759 ms
5,184 KB
testcase_14 AC 1,080 ms
5,840 KB
testcase_15 AC 908 ms
5,772 KB
testcase_16 AC 1,015 ms
5,784 KB
testcase_17 AC 1,093 ms
5,932 KB
testcase_18 AC 1,704 ms
7,032 KB
testcase_19 AC 1,709 ms
7,040 KB
testcase_20 AC 1,707 ms
7,036 KB
testcase_21 AC 1,704 ms
7,032 KB
testcase_22 AC 1,707 ms
7,032 KB
testcase_23 AC 940 ms
5,532 KB
testcase_24 TLE -
testcase_25 AC 40 ms
4,728 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1,689 ms
7,096 KB
testcase_28 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
#include <atcoder/all>

#define pub push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;


using namespace atcoder;
using mint = modint998244353;
using mint2 = modint1000000007;

constexpr long long INF = (1LL << 60);
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589;


template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
T sq(T x) {
    return x * x;
}

std::string zfill(int n, const int width)
{
    std::stringstream ss;
    ss << std::setw(width) << std::setfill('0') << n;
    return ss.str();
}


//多倍長整数を(string→vector)に変換
vector<ll> digit(string s) {
    ll n = s.size();
    vector<ll> d(n);
    rep(i, n) {
        d[i] = s[i] - '0';
    }
    return d;
}


//多倍長整数の足し算
vector<ll> adds(vector<ll> s, vector<ll> t) {
    ll n = s.size();
    ll m = t.size();
    if (n > m) { swap(s, t); n = s.size(); m = t.size(); }
    reverse(ALL(s));
    reverse(ALL(t));
    rep(i, m - n) {
        s.pub(0);
    }
    bool kuriage = false;
    rep(i, m) {
        ll a = s[i];
        ll b = t[i];
        ll c = a + b;
        if (kuriage) {
            c++;
        }
        if (c >= 10) {
            c -= 10; kuriage = true;
        }
        else {
            kuriage = false;
        }
        t[i] = c;
    }
    if (kuriage) {
        t.pub(1);
    }
    reverse(ALL(t));
    return t;
}


vector<ll> carry_and_fix(vector<ll> digit) {
    int N = digit.size();

    for (int i = 0; i < N - 1; ++i) {
        // 繰り上がり処理 (K は繰り上がりの回数)
        if (digit[i] >= 10) {
            int K = digit[i] / 10;
            digit[i] -= K * 10;
            digit[i + 1] += K;
        }
        // 繰り下がり処理 (K は繰り下がりの回数)
        if (digit[i] < 0) {
            int K = (-digit[i] - 1) / 10 + 1;
            digit[i] += K * 10;
            digit[i + 1] -= K;
        }
    }
    // 一番上の桁が 10 以上なら、桁数を増やすことを繰り返す
    while (digit.back() >= 10) {
        int K = digit.back() / 10;
        digit.back() -= K * 10;
        digit.push_back(K);
    }
    // 1 桁の「0」以外なら、一番上の桁の 0 (リーディング・ゼロ) を消す
    while (digit.size() >= 2 && digit.back() == 0) {
        digit.pop_back();
    }
    reverse(ALL(digit));
    return digit;
}


//多倍長整数の掛け算(s × t) 計算量は N(|s||t|)?
vector<ll> mul(vector<ll> s, vector<ll> t) {
    reverse(ALL(s));
    reverse(ALL(t));
    ll NA = s.size();
    ll NB = t.size();
    vector<ll> res(NA + NB - 1);
    for (int i = 0; i < NA; ++i) {
        for (int j = 0; j < NB; ++j) {
            res[i + j] += s[i] * t[j];
        }
    }
    return carry_and_fix(res);
}


/*  make_is_prime(N)
    入力:整数 N
    出力:N までの数字が素数か判定したベクトル(i番目がtrueならiは素数)
    計算量:O(nloglogn)
*/
vector< bool > prime_table(int n) {
    vector< bool > prime(n + 1, true);
    if (n >= 0) prime[0] = false;
    if (n >= 1) prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!prime[i]) continue;
        for (int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}


/*  divisor(n)
    入力:整数 n
    出力:nのすべての約数
    計算量:O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}


int main() {
    //cout << fixed << setprecision(10);
    ll N, M; cin >> N >> M;
    vector<ll> A(N);
    vector<ll> cnt(M+1);
    rep(i, N) {
        cin >> A[i];
        vector<ll> d = divisor(A[i]);
        for (auto a : d) {
            cnt[a]++;
        }
    }
    vector<mint> ans(M + 1);
    for (int i = M; i >= 1; i--) {
        mint p = pow_mod(2, cnt[i], 998244353) - 1;
        ans[i] += p;
        vector<ll> d = divisor(i);
        for (auto a : d) {
            if (a == i) {
                continue;
            }
            else {
                ans[a] -= ans[i];
            }
        }
        
    }
    rep(i, M) {
        cout << ans[i + 1].val() << endl;
    }

}







0