結果

問題 No.2075 GCD Subsequence
ユーザー tktk_snsntktk_snsn
提出日時 2022-09-17 12:10:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,168 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 108,612 KB
実行使用メモリ 9,684 KB
最終ジャッジ日時 2023-08-23 17:38:34
合計ジャッジ時間 6,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,536 KB
testcase_01 AC 10 ms
7,528 KB
testcase_02 AC 9 ms
7,592 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 WA -
testcase_29 AC 9 ms
7,604 KB
testcase_30 AC 10 ms
7,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <string>
#include <bitset>
#include <assert.h>

// #define _GLIBCXX_DEBUG
// #define _LIBCPP_DEBUG 0
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define revrep(i, n) for(int i = (int)(n -1); i >= 0; --i)
#define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i)
#define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i+=int(step))
#define popcnt(x) __builtin_popcountll(x)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); }
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};

const ll mod = 998244353;


vector<int> prime_sieve(int n){
    vector<int> sieve(n+1, 0), prime;
    for (int i=2; i<n+1; i++){
        if (sieve[i]==0){
            sieve[i] = i;
            prime.emplace_back(i);
        }
        for (int p: prime){
            if (p > sieve[i] || i * p > n) break;
            sieve[i * p] = p;
        }
    }
    return sieve;
}


int main() {
    int n; 
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    auto sieve = prime_sieve(1e6);
    map<int, ll> mp;
    ll ans = 0;
    for (auto x: a) {
        set<int> s;
        while (sieve[x] != 0) {
            s.insert(sieve[x]);
            x /= sieve[x];
        }
        ll cnt = 1;
        for(auto it=s.begin(); it!=s.end(); ++it) {
            cnt += mp[*it];
            if (cnt >= mod) cnt -= mod;
        }
        for(auto it=s.begin(); it!=s.end(); ++it) {
            mp[*it] += cnt;
            if (mp[*it] >= mod) mp[*it] -= mod;
        }
        ans += cnt;
        if (ans >= mod) ans -= mod;
    }
    cout << ans << endl;
}
0