結果

問題 No.2578 Jewelry Store
ユーザー suisensuisen
提出日時 2023-01-13 17:57:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,469 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 85,872 KB
実行使用メモリ 9,876 KB
最終ジャッジ日時 2023-12-05 23:33:32
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 40 ms
6,548 KB
testcase_03 AC 42 ms
6,548 KB
testcase_04 AC 41 ms
6,548 KB
testcase_05 AC 18 ms
6,548 KB
testcase_06 AC 42 ms
6,548 KB
testcase_07 AC 38 ms
6,548 KB
testcase_08 AC 44 ms
6,548 KB
testcase_09 AC 36 ms
6,548 KB
testcase_10 AC 39 ms
6,548 KB
testcase_11 AC 20 ms
6,548 KB
testcase_12 AC 42 ms
6,548 KB
testcase_13 AC 31 ms
6,548 KB
testcase_14 AC 29 ms
6,548 KB
testcase_15 AC 33 ms
6,548 KB
testcase_16 AC 41 ms
6,548 KB
testcase_17 AC 39 ms
6,548 KB
testcase_18 AC 33 ms
6,548 KB
testcase_19 AC 39 ms
6,548 KB
testcase_20 AC 40 ms
6,548 KB
testcase_21 AC 42 ms
6,548 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

mint solve_naive(uint32_t n, uint64_t m, std::vector<uint64_t> a, std::vector<uint32_t> w) {
    {
        std::vector<uint64_t> a2;
        std::vector<uint32_t> w2;
        for (uint32_t i = 0; i < n; ++i) if (m % a[i] == 0) {
            a2.push_back(a[i]);
            w2.push_back(w[i]);
        }
        a.swap(a2);
        w.swap(w2);
        n = a.size();
    }

    mint ans = 0;
    for (uint32_t s = 1; s < uint32_t(1) << std::min(n, 30u); ++s) {
        mint prod = 1;
        uint64_t l = 1;
        for (uint32_t i = 0; i < n; ++i) if ((s >> i) & 1) {
            l = std::lcm(l, a[i]);
            prod *= w[i];
        }
        if (l == m) {
            ans += prod;
        }
    }
    return ans;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    uint32_t t;
    uint64_t m;
    std::cin >> t >> m;

    for (uint32_t testcase = 0; testcase < t; ++testcase) {
        uint32_t n;
        std::cin >> n;

        uint32_t x0, c, d;
        std::cin >> x0 >> c >> d;

        std::vector<uint32_t> w(n);
        w[0] = x0;
        for (uint32_t i = 1; i < n; ++i) {
            w[i] = (c * mint(w[i - 1]) + d).val();
        }

        std::vector<uint64_t> a(n);
        for (auto &e : a) std::cin >> e;

        std::cout << solve_naive(n, m, a, w).val() << '\n';
    }

    return 0;
}
0