結果

問題 No.1529 Constant Lcm
ユーザー Manuel1024Manuel1024
提出日時 2021-06-04 21:37:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 3,000 ms
コード長 1,334 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 83,192 KB
実行使用メモリ 10,924 KB
最終ジャッジ日時 2023-08-12 12:08:52
合計ジャッジ時間 5,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 304 ms
10,152 KB
testcase_11 AC 118 ms
5,980 KB
testcase_12 AC 7 ms
4,384 KB
testcase_13 AC 258 ms
9,144 KB
testcase_14 AC 143 ms
7,092 KB
testcase_15 AC 168 ms
7,236 KB
testcase_16 AC 139 ms
6,132 KB
testcase_17 AC 70 ms
4,928 KB
testcase_18 AC 79 ms
4,808 KB
testcase_19 AC 153 ms
6,936 KB
testcase_20 AC 355 ms
10,864 KB
testcase_21 AC 358 ms
10,896 KB
testcase_22 AC 367 ms
10,924 KB
testcase_23 AC 354 ms
10,788 KB
testcase_24 AC 334 ms
10,748 KB
testcase_25 AC 315 ms
10,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;

ll modpow(ll a, ll x){
    ll ans = 1;
    while(x > 0){
        if(x & 1){
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        x >>= 1;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector<int> isprime(n+1);
    for(int i = 0; i <= n; i++) isprime[i] = i;
    for(int i = 2; i <= n; i++){
        if(isprime[i] == i){
            for(int j = 2; i*j <= n; j++){
                if(isprime[i*j] > i) isprime[i*j] = i;
            }
        }
    }

    vector<int> cnt(n+1, 0);
    for(int i = 1; i < n; i++){
        int k = i;
        map<int, int> fac;
        while(k > 1){
            if(fac.count(isprime[k])) fac[isprime[k]]++;
            else fac[isprime[k]] = 1;
            k /= isprime[k];
        }
        k = n-i;
        while(k > 1){
            if(fac.count(isprime[k])) fac[isprime[k]]++;
            else fac[isprime[k]] = 1;
            k /= isprime[k];
        }
        for(auto &p: fac){
            if(cnt[p.first] < p.second) cnt[p.first] = p.second;
        }
    }

    ll ans = 1;
    for(int i = 2; i < n; i++){
        ans *= modpow(i, cnt[i]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0