結果

問題 No.1529 Constant Lcm
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-13 22:00:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 777 ms / 3,000 ms
コード長 1,366 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 118,048 KB
実行使用メモリ 15,984 KB
最終ジャッジ日時 2023-09-04 09:26:19
合計ジャッジ時間 11,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 673 ms
14,620 KB
testcase_11 AC 240 ms
7,748 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 560 ms
13,316 KB
testcase_14 AC 326 ms
9,616 KB
testcase_15 AC 376 ms
10,032 KB
testcase_16 AC 283 ms
8,416 KB
testcase_17 AC 140 ms
6,208 KB
testcase_18 AC 157 ms
6,136 KB
testcase_19 AC 353 ms
9,732 KB
testcase_20 AC 777 ms
15,956 KB
testcase_21 AC 756 ms
15,700 KB
testcase_22 AC 754 ms
15,812 KB
testcase_23 AC 775 ms
15,720 KB
testcase_24 AC 765 ms
15,984 KB
testcase_25 AC 726 ms
15,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

const ll modc = 998244353;
vector<ll> spf;
map<ll, ll> prime;
map<ll, ll> pmax;

void osa_k(ll n){
    spf.resize(n+1);
    for (ll i=0; i<=n; i++) spf[i] = i;
    for (ll i=2; i*i<=n; i++){
        if (spf[i] == i){
            for (ll j=2; i*j <= n; j++){
                spf[i*j] = min(spf[i*j], i);
            }
        }
    }
}

void prime_factor(ll n){
    while(n != 1){
        prime[spf[n]]++;
        n /= spf[n];
    }
}

ll mod_exp(ll b, ll e, ll m){
    if (e > 0 && b == 0) return 0;
    ll ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){

    ll N, ans=1;
    cin >> N;
    osa_k(N);

    for (ll i=1; i<=N/2; i++){
        prime_factor(i);
        prime_factor(N-i);
        for (auto [x, y] : prime){
            if (!pmax.count(x)) pmax[x] = y;
            else pmax[x] = max(pmax[x], y);
        }
        prime.clear();
    }

    for (auto [x, y] : pmax){
        ans *= mod_exp(x, y, modc);
        ans %= modc;
    }

    cout << ans << endl;

    return 0;
}
0