結果

問題 No.1529 Constant Lcm
ユーザー nawawannawawan
提出日時 2021-06-04 20:48:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,112 ms / 3,000 ms
コード長 2,847 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 84,260 KB
実行使用メモリ 10,760 KB
最終ジャッジ日時 2023-08-12 10:16:23
合計ジャッジ時間 13,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,864 KB
testcase_01 AC 12 ms
6,916 KB
testcase_02 AC 11 ms
6,912 KB
testcase_03 AC 11 ms
6,864 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 11 ms
6,956 KB
testcase_06 AC 11 ms
6,860 KB
testcase_07 AC 11 ms
6,996 KB
testcase_08 AC 11 ms
6,920 KB
testcase_09 AC 11 ms
6,900 KB
testcase_10 AC 978 ms
10,428 KB
testcase_11 AC 351 ms
8,500 KB
testcase_12 AC 25 ms
6,968 KB
testcase_13 AC 805 ms
9,972 KB
testcase_14 AC 473 ms
8,764 KB
testcase_15 AC 543 ms
9,108 KB
testcase_16 AC 413 ms
8,788 KB
testcase_17 AC 222 ms
8,028 KB
testcase_18 AC 240 ms
7,944 KB
testcase_19 AC 515 ms
8,996 KB
testcase_20 AC 1,103 ms
10,592 KB
testcase_21 AC 1,082 ms
10,684 KB
testcase_22 AC 1,087 ms
10,668 KB
testcase_23 AC 1,112 ms
10,760 KB
testcase_24 AC 1,101 ms
10,760 KB
testcase_25 AC 1,054 ms
10,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
template<const int MOD> struct modint{
    long long val;
    modint(): val(0) {}
    modint(long long x){
        if(x < 0) val = x % MOD + MOD;
        else val = x % MOD;
    }
    modint(const modint &t){
        val = t.val;
    }
    modint& operator =(const modint m){
        val = m.val;
        return *this;
    }
    modint operator -(){
        return modint(-val);
    }
    modint& operator-=(const modint &m){
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    modint& operator+=(const modint &m){
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    modint& operator*=(const modint &m){
        val *= m.val;
        val %= MOD;
        return *this;
    }
    modint& operator/=(modint m){
        *this *= m.inv();
        return *this;
    }
    modint inv(){
        long long x = 1, y = 0;
        long long a = val, b = MOD;
        while(b != 0){
            long long t = a / b;
            a -= t * b;
            x -= t * y;
            swap(a, b);
            swap(x, y);
        }
        x %= MOD;
        if(x < 0) x += MOD;
        return modint(x);
    }
    modint pow(long long k){
        long long res = 1;
        long long v = val;
        while(k > 0){
            if(k & 1) res = res * v % MOD;
            v = v * v % MOD;
            k >>= 1;
        }
        return modint(res);
    }
    modint operator==(const modint &m){
        return val == m.val;
    }
    modint operator+(const modint &m){
        return modint(*this) += m;
    }
    modint operator-(const modint &m){
        return modint(*this) -= m;
    }
    modint operator*(const modint &m){
        return modint(*this) *= m;
    }
    modint operator/(const modint &m){
        return modint(*this) /= m;
    }
    bool operator!=(const modint &m){
        return modint(*this).val != m.val;
    }
    bool operator!=(const int &m){
        return modint(*this).val != m;
    }
};
const int MOD = 998244353;
using mint = modint<MOD>;
int main(){
    int N;
    cin >> N;
    vector<int> fac(1000010, -1);
    fac[1] = 1;
    for(int i = 2; i < 1000010; i++){
        if(fac[i] != -1) continue;
        int t = i;
        while(t < 1000010){
            fac[t] = i;
            t += i;
        }
    }
    map<int, int> m;
    for(int i = 1; i < N; i++){
        map<int, int> t;
        for(int j = i; j != 1; j /= fac[j]){
            t[fac[j]]++;
        }
        for(int j = N - i; j != 1; j /= fac[j]){
            t[fac[j]]++;
        }
        for(auto v: t){
            m[v.first] = max(m[v.first], v.second);
        }
    }
    mint ans = 1;
    for(auto v: m){
        mint t = v.first;
        ans *= t.pow(v.second);
    }
    cout << ans.val << endl;
}
0