結果

問題 No.1529 Constant Lcm
ユーザー OmameBeansOmameBeans
提出日時 2021-07-06 22:47:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 173,420 KB
実行使用メモリ 12,296 KB
最終ジャッジ日時 2023-09-14 04:32:37
合計ジャッジ時間 6,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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);}

map<ll,ll> f(ll N) {
    map<ll,ll> mp;
    for(ll i = 2; i*i <= N; i++) {
        if(N%i == 0) {
            ll ex = 0;
            while(N%i == 0) {
                ex++;
                N /= i;
            }
            mp[i] += ex;
        }
    }
    if(N!=1) mp[N]++;
    return mp;
}

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;
}

int main() {
    ll N; cin >> N;
    map<ll,ll> LCM;

    for(ll i = 1; i <= N-1; i++) {
        map<ll,ll> mp;
        for(auto e : f(i)) mp[e.first] += e.second;
        for(auto e : f(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