結果

問題 No.1529 Constant Lcm
ユーザー OmameBeansOmameBeans
提出日時 2021-07-06 23:53:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,412 ms / 3,000 ms
コード長 2,146 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 177,160 KB
実行使用メモリ 16,072 KB
最終ジャッジ日時 2023-09-14 04:33:04
合計ジャッジ時間 16,722 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
10,764 KB
testcase_01 AC 11 ms
10,896 KB
testcase_02 AC 10 ms
10,884 KB
testcase_03 AC 9 ms
10,692 KB
testcase_04 AC 10 ms
10,712 KB
testcase_05 AC 10 ms
10,704 KB
testcase_06 AC 9 ms
10,700 KB
testcase_07 AC 10 ms
10,828 KB
testcase_08 AC 9 ms
10,952 KB
testcase_09 AC 10 ms
11,064 KB
testcase_10 AC 1,211 ms
15,260 KB
testcase_11 AC 452 ms
12,804 KB
testcase_12 AC 28 ms
11,016 KB
testcase_13 AC 1,035 ms
14,848 KB
testcase_14 AC 586 ms
13,384 KB
testcase_15 AC 659 ms
13,744 KB
testcase_16 AC 548 ms
13,256 KB
testcase_17 AC 263 ms
12,060 KB
testcase_18 AC 287 ms
12,012 KB
testcase_19 AC 635 ms
13,644 KB
testcase_20 AC 1,373 ms
16,072 KB
testcase_21 AC 1,372 ms
15,824 KB
testcase_22 AC 1,361 ms
15,832 KB
testcase_23 AC 1,390 ms
15,908 KB
testcase_24 AC 1,412 ms
15,724 KB
testcase_25 AC 1,334 ms
15,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 998244353;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

ll modpow(ll a, ll n) {
    if(n == 0) return 1;
    auto t = modpow(a,n/2);
    t = t*t;
    t %= MOD;
    if(n & 1) {
        t *= a;
        t %= MOD;
    }
    return t;
}

template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    ll N; cin >> N;
    map<ll,ll> LCM;
    PrimeFact<ll> fp(1000010);
    for(ll i = 1; i <= N-1; i++) {
        map<ll,ll> mp;
        for(auto e : fp.get(i)) mp[e.first] += e.second;
        for(auto e : fp.get(N-i)) mp[e.first] += e.second;
        for(auto e : mp) {
            //cout << e.first << " " << e.second << endl;
            LCM[e.first] = max(LCM[e.first],e.second);
        }
    }

    ll ans = 1;
    for(auto e : LCM) {
        ans *= modpow(e.first, e.second);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}
0