結果

問題 No.1529 Constant Lcm
ユーザー nawawannawawan
提出日時 2021-06-04 20:46:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,851 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 84,508 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-30 00:24:20
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 14 ms
7,040 KB
testcase_02 AC 12 ms
7,168 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 13 ms
7,296 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 504 ms
10,496 KB
testcase_11 AC 187 ms
8,704 KB
testcase_12 AC 20 ms
7,168 KB
testcase_13 WA -
testcase_14 AC 250 ms
9,216 KB
testcase_15 AC 285 ms
9,344 KB
testcase_16 AC 220 ms
8,704 KB
testcase_17 AC 118 ms
8,192 KB
testcase_18 AC 129 ms
8,192 KB
testcase_19 AC 270 ms
9,088 KB
testcase_20 AC 572 ms
10,880 KB
testcase_21 AC 560 ms
10,880 KB
testcase_22 AC 559 ms
10,880 KB
testcase_23 AC 572 ms
10,752 KB
testcase_24 AC 565 ms
10,752 KB
testcase_25 AC 554 ms
10,752 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 / 2; 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