結果

問題 No.2075 GCD Subsequence
ユーザー otoshigootoshigo
提出日時 2022-09-17 16:29:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,806 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 207,540 KB
実行使用メモリ 20,408 KB
最終ジャッジ日時 2023-08-23 17:49:11
合計ジャッジ時間 12,056 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
11,072 KB
testcase_01 AC 35 ms
11,108 KB
testcase_02 AC 35 ms
11,096 KB
testcase_03 AC 34 ms
11,012 KB
testcase_04 AC 34 ms
11,044 KB
testcase_05 AC 34 ms
10,912 KB
testcase_06 AC 34 ms
11,100 KB
testcase_07 AC 36 ms
11,016 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 570 ms
11,884 KB
testcase_29 AC 35 ms
10,992 KB
testcase_30 AC 35 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = (n) - 1; i >= 0; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

struct Eratosthenes{
    vector<bool> prime;
    vector<int> factor, mobius;
    Eratosthenes(int n) : prime(n + 1, true), factor(n + 1, -1), mobius(n + 1, 1){
        prime[1] = false;
        factor[1] = 1;
        for (int p = 2; p <= n; p++){
            if (!prime[p]){
                continue;
            }
            factor[p] = p;
            mobius[p] = -1;
            for (int q = 2 * p; q <= n; q += p){
                prime[q] = false;
                factor[q] = p;
                if ((q / p) % p == 0){
                    mobius[q] = 0;
                } else{
                    mobius[q] = -mobius[q];
                }
            }
        }
    }
    vector<pair<int, int>> factorize(int n){
        vector<pair<int, int>> pf;
        while (n > 1){
            int p = factor[n], exp = 0;
            while (n % p == 0){
                n /= p;
                exp++;
            }
            pf.push_back(make_pair(p, exp));
        }
        return pf;
    }
    vector<int> divisors(int n){
        vector<int> div = {1};
        vector<pair<int, int>> pf = factorize(n);
        for (auto [p, e] : pf){
            int l = div.size();
            for (int i = 0; i < l; i++){
                int q = p;
                for (int j = 0; j < e; j++){
                    div.push_back(div[i] * q);
                    q *= p;
                }
            }
        }
        //sort(div.begin(), div.end());
        return div;
    }
    int euler(int n){
        int e = n;
        vector<pair<int, int>> pf = factorize(n);
        for (int i = 0; i < pf.size(); i++){
            e /= pf[i].first;
            e *= pf[i].first - 1;
        }
        return e;
    }
};

const int MOD = 998244353;
int n, A[200010];
ll dp[1000010], S[100010];

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> n;
    ll s = 0;
    Eratosthenes er(1e6 + 1);
    rep(i, n){
        cin >> A[i];
        ll x = 1 + s;
        int a = 1;
        vector<int> div = er.divisors(A[i]);
        for (auto a : div){
            x -= er.mobius[a] * S[a];
            x %= MOD;
            if (x < 0){
                x += MOD;
            }
        }
        dp[A[i]] += x;
        dp[A[i]] %= MOD;
        s += x;
        s %= MOD;
        for (auto a : div){
            S[a] += x;
            S[a] %= MOD;
        }
    }
    cout << s << "\n";
}
0