結果

問題 No.1396 Giri
ユーザー tabae326tabae326
提出日時 2021-02-14 21:52:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 1,962 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 212,324 KB
実行使用メモリ 15,828 KB
最終ジャッジ日時 2023-09-29 15:12:08
合計ジャッジ時間 8,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
10,524 KB
testcase_01 AC 14 ms
10,556 KB
testcase_02 AC 618 ms
15,696 KB
testcase_03 AC 15 ms
10,552 KB
testcase_04 AC 13 ms
10,488 KB
testcase_05 AC 618 ms
15,688 KB
testcase_06 AC 15 ms
10,704 KB
testcase_07 AC 15 ms
10,640 KB
testcase_08 AC 13 ms
10,688 KB
testcase_09 AC 14 ms
10,624 KB
testcase_10 AC 14 ms
10,596 KB
testcase_11 AC 14 ms
10,544 KB
testcase_12 AC 15 ms
10,544 KB
testcase_13 AC 14 ms
10,484 KB
testcase_14 AC 14 ms
10,652 KB
testcase_15 AC 14 ms
10,736 KB
testcase_16 AC 14 ms
10,636 KB
testcase_17 AC 18 ms
11,044 KB
testcase_18 AC 49 ms
11,352 KB
testcase_19 AC 301 ms
13,604 KB
testcase_20 AC 430 ms
14,360 KB
testcase_21 AC 553 ms
15,172 KB
testcase_22 AC 612 ms
15,692 KB
testcase_23 AC 621 ms
15,696 KB
testcase_24 AC 621 ms
15,748 KB
testcase_25 AC 621 ms
15,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

/* --------- ここから --------- */
struct osa_k {
    using _ll = long long;

    #define PRIME_FACTORIZE_MAX 1000010
    vector<_ll> primes;

    osa_k() {
        primes.resize((PRIME_FACTORIZE_MAX));
        for(_ll i = 0; i < PRIME_FACTORIZE_MAX; i++) {
            primes[i] = 1;
        }
        for(_ll i = 2; i < PRIME_FACTORIZE_MAX; i++) {
            if(primes[i] != 1) continue;
            for(_ll j = i; j <= PRIME_FACTORIZE_MAX; j += i) {
                primes[j] = i;
            }
        }
    }

    vector<pair<_ll,_ll>> factorize(_ll n){
        vector<pair<_ll,_ll>> res;
        while(n != 1) {
            _ll cur = primes[n];
            _ll cnt = 0;
            while(n % cur == 0) {
                n /= cur;
                cnt++;
            }
            res.push_back({cur, cnt});
        }
        reverse(res.begin(), res.end());
        return res;
    }
} osa_k;

vector<pair<long long, long long>>factorize(long long n) {
    return osa_k.factorize(n);
}
/* --------- ここまで --------- */

void solve() {
    ll n;
    cin >> n;
    ll mx = 1;
    for(ll i = n; i >= 2; i--) {
        if(osa_k.primes[i] == i) {
            mx = i;
            break;
        }
    }
    map<ll,ll> mp;
    rep(i, 2, n+1) {
        if(mx == i) continue;
        auto v = factorize(i);
        for(auto [a, p] : v) mp[a] = max(mp[a], p);
    } 
    const ll mod = 998244353;
    auto P = [&](ll a, ll p) {
        ll x = a, res = 1;
        while(p) {
            if(p & 1) (res *= x) %= mod;
            (x *= x) %= mod;
            p /= 2;
        }
        return res;
    };
    ll ans = 1;
    for(auto [a, p] : mp) {
        (ans *= P(a, p)) %= mod;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
0