結果

問題 No.1529 Constant Lcm
ユーザー KudeKude
提出日時 2021-06-04 20:13:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,091 ms / 3,000 ms
コード長 2,544 bytes
コンパイル時間 4,418 ms
コンパイル使用メモリ 270,396 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-08-12 08:52:18
合計ジャッジ時間 16,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,204 KB
testcase_01 AC 9 ms
7,352 KB
testcase_02 AC 8 ms
7,132 KB
testcase_03 AC 7 ms
7,040 KB
testcase_04 AC 7 ms
7,292 KB
testcase_05 AC 7 ms
7,264 KB
testcase_06 AC 8 ms
7,260 KB
testcase_07 AC 7 ms
7,208 KB
testcase_08 AC 8 ms
7,088 KB
testcase_09 AC 7 ms
7,152 KB
testcase_10 AC 934 ms
10,620 KB
testcase_11 AC 337 ms
8,768 KB
testcase_12 AC 21 ms
7,616 KB
testcase_13 AC 788 ms
10,120 KB
testcase_14 AC 462 ms
9,400 KB
testcase_15 AC 528 ms
9,352 KB
testcase_16 AC 410 ms
8,840 KB
testcase_17 AC 209 ms
8,372 KB
testcase_18 AC 228 ms
8,412 KB
testcase_19 AC 497 ms
9,360 KB
testcase_20 AC 1,063 ms
11,040 KB
testcase_21 AC 1,063 ms
11,032 KB
testcase_22 AC 1,057 ms
11,040 KB
testcase_23 AC 1,091 ms
10,936 KB
testcase_24 AC 1,049 ms
10,912 KB
testcase_25 AC 1,022 ms
10,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

std::pair<std::vector<int>,std::vector<int>> primes_lpf(const int n) {
    std::pair<std::vector<int>,std::vector<int>> rv;
    std::vector<int>& primes = rv.first;
    std::vector<int>& lpf = rv.second;
    primes.reserve(n / 10);
    lpf.resize(n + 1);
    for(int i = 2; i <= n; i += 2) lpf[i] = 2;
    for(int i = 3; i <= n; i += 6) lpf[i] = 3;
    if (2 <= n) primes.push_back(2);
    if (3 <= n) primes.push_back(3);
    // 5 * x <= n, x <= floor(n / 5)
    const int n5 = n / 5;
    int x = 5;
    bool one_mod6 = false;
    // x_1 <= n5, x_2 = x_1 + 2 <= n5 + 2 <= n
    for(; x <= n5; one_mod6 = !one_mod6, x += (one_mod6 ? 2 : 4)) {
        if (lpf[x] == 0) {
            lpf[x] = x;
            primes.push_back(x);
        }
        int px = lpf[x];
        for(int i = 2;; ++i) {
            int q = primes[i];
            int y = q * x;
            if (y > n) break;
            lpf[y] = q;
            if (q == px) break;
        }
    }
    for(; x <= n; one_mod6 = !one_mod6, x += (one_mod6 ? 2 : 4)) {
        if (lpf[x] == 0) {
            lpf[x] = x;
            primes.push_back(x);
        }
    }
    return rv;
}

auto [primes, lpf] = primes_lpf(1000000);

// global variable lpf must be defined
std::vector<std::pair<int,int>> factorize(int n) {
    std::vector<std::pair<int,int>> fs;
    while(n > 1) {
        int p = lpf[n];
        int cnt = 0;
        do {n /= p; cnt++;} while(n % p == 0);
        fs.emplace_back(p, cnt);
    }
    return fs;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> d;
    for(int i = 1; i <= n - 1; i++) {
        map<int, int> mp;
        for(int x: {i, n - i}) {
            for(auto [p, cnt]: factorize(x)) {
                mp[p] += cnt;
            }
        }
        for(auto [p, cnt]: mp) {
            chmax(d[p], cnt);
        }
    }
    mint ans = 1;
    for(auto [p, cnt]: d) ans *= mint::raw(p).pow(cnt);
    cout << ans.val() << '\n';
}
0