結果

問題 No.1529 Constant Lcm
ユーザー 👑 KazunKazun
提出日時 2021-04-29 01:47:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,299 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 84,816 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-18 16:59:41
合計ジャッジ時間 5,244 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,084 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 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 <iostream>
#include <vector>
#include <map>

using namespace std;
using ll=long long;

vector<pair<ll,ll>> Prime_Factorization(ll N) {
    vector<pair<ll,ll>> R;
    ll e=0;
    
    while (N%2==0){
        e++;
        N/=2;
    }
    R.push_back({2,e});
    
    e=0;
    while (N%3==0){
        e++;
        N/=3;
    }
    R.push_back({3,e});
    
    ll p=5,f=0;
    while (p*p<=N) {
        if (N % p==0){
            ll e=0;
            while (N % p == 0){
                e++;
                N/=p;
            }
    
            R.push_back({p,e});
        }
        
        p+=2+2*f;
        f^=1;
    }

    if (N != 1) R.push_back({N, 1});
    
    return R;
}

ll pow_mod(ll a,ll p,ll m){
    ll x=1;
    while (p){
        if (p&1){
            x*=a;
            x%=m;
        }
        a*=a; a%=m;
        p>>=1;
    }
    return x;
}

ll max(ll a, ll b){
    if (a>b) return a;
    else return b;
}

int main(){
    ll N;
    ll mod=998244353;
    vector<pair<ll,ll>> R;
    map <ll,ll> D;
    cin >> N;

    for (int i=1; 2*i<=(N+1); i++){
        R=Prime_Factorization(i*(N-i));
        for (auto x:R) D[x.first]=max(D[x.first],x.second);
    }
    
    ll a=1;
    for (auto x:D){
        a*=pow_mod(x.first,x.second,mod);
        a%=mod;
    }

    cout << a << endl;
}
0