結果

問題 No.1529 Constant Lcm
ユーザー sten_sansten_san
提出日時 2021-06-04 20:34:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 686 ms / 3,000 ms
コード長 2,566 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 217,572 KB
実行使用メモリ 76,812 KB
最終ジャッジ日時 2023-08-12 09:45:07
合計ジャッジ時間 10,374 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 609 ms
70,196 KB
testcase_11 AC 213 ms
29,444 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 495 ms
60,472 KB
testcase_14 AC 298 ms
40,256 KB
testcase_15 AC 340 ms
42,312 KB
testcase_16 AC 253 ms
33,340 KB
testcase_17 AC 130 ms
19,668 KB
testcase_18 AC 143 ms
21,292 KB
testcase_19 AC 320 ms
41,236 KB
testcase_20 AC 686 ms
76,812 KB
testcase_21 AC 659 ms
76,544 KB
testcase_22 AC 684 ms
76,724 KB
testcase_23 AC 685 ms
76,408 KB
testcase_24 AC 663 ms
76,488 KB
testcase_25 AC 645 ms
76,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
    int n; cin >> n;

    auto sieve = vec<int>(uns, n + 1);
    iota(begin(sieve), end(sieve), 0);

    for (int i = 2; i <= n / i; ++i) {
        if (sieve[i] != i) {
            continue;
        }

        for (int j = i * i; j <= n; j += i) {
            if (sieve[j] == j) {
                sieve[j] = i;
            }
        }
    }

    auto p = vec<tuple<int, int>>(uns, n + 1, 0);

    for (int i = 2; i <= n; ++i) {
        auto &pf = p[i];

        int x = i;
        while (x != 1) {
            int d = sieve[x];

            int c = 0;
            while (x % d == 0) {
                ++c;
                x /= d;
            }

            pf.push_back({ d, c });
        }
    }

    map<int, int> f;
    for (int i = 1; i <= n - 1; ++i) {
        auto iter1 = begin(p[i]);
        auto iter2 = begin(p[n - i]);

        while (iter1 != end(p[i]) && iter2 != end(p[n - i])) {
            auto [a1, b1] = *iter1;
            auto [a2, b2] = *iter2;

            if (a1 < a2) {
                chmax(f[a1], b1);
                ++iter1;
                continue;
            }

            if (a1 > a2) {
                chmax(f[a2], b2);
                ++iter2;
                continue;
            }

            chmax(f[a1], b1 + b2);
            ++iter1; ++iter2;
        }

        while (iter1 != end(p[i])) {
            chmax(f[get<0>(*iter1)], get<1>(*iter1));
            ++iter1;
        }

        while (iter2 != end(p[n - i])) {
            chmax(f[get<0>(*iter2)], get<1>(*iter2));
            ++iter2;
        }
    }

    mint ans = 1;
    for (auto [a, b] : f) {
        ans *= mint(a).pow(b);
    }

    cout << ans.val() << endl;
}

0