結果

問題 No.1529 Constant Lcm
ユーザー HaaHaa
提出日時 2021-06-04 20:20:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,751 ms / 3,000 ms
コード長 1,182 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 175,724 KB
実行使用メモリ 195,512 KB
最終ジャッジ日時 2023-08-12 09:15:18
合計ジャッジ時間 21,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1,571 ms
178,348 KB
testcase_11 AC 589 ms
71,776 KB
testcase_12 AC 15 ms
6,480 KB
testcase_13 AC 1,330 ms
152,976 KB
testcase_14 AC 818 ms
99,364 KB
testcase_15 AC 884 ms
104,972 KB
testcase_16 AC 689 ms
81,504 KB
testcase_17 AC 353 ms
45,800 KB
testcase_18 AC 371 ms
49,436 KB
testcase_19 AC 855 ms
102,084 KB
testcase_20 AC 1,735 ms
195,404 KB
testcase_21 AC 1,751 ms
195,512 KB
testcase_22 AC 1,707 ms
195,512 KB
testcase_23 AC 1,710 ms
195,308 KB
testcase_24 AC 1,704 ms
195,392 KB
testcase_25 AC 1,674 ms
195,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    int n; cin >> n;
    vector<map<int,int>> mp(n+1);
    VI f(n+1,0);
    for(int i=2;i<=n;i++){
        if(f[i]) continue;
        for(int j=i;j<=n;j+=i){
            f[j]=1;
            int x=j;
            while(x%i==0){
                x/=i;
                mp[j][i]++;
            }
        }
    }
    vector<int> cnt(n+1,0);
    for(int i=1;i<n;i++){
        map<int,int> mps;
        for(auto p:mp[i]){
            mps[p.first]+=p.second;
        }
        for(auto p:mp[n-i]){
            mps[p.first]+=p.second;
        }
        for(auto p:mps){
            cnt[p.first]=max(cnt[p.first],p.second);
        }
    }
    ll ans=1;
    for(int i=2;i<=n;i++){
        ans=ans*power(i,cnt[i])%MOD;
    }
    cout << ans << endl;
    return 0;
}
0