結果

問題 No.1529 Constant Lcm
ユーザー HaaHaa
提出日時 2021-06-04 20:23:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,164 ms / 3,000 ms
コード長 1,202 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 178,644 KB
実行使用メモリ 268,288 KB
最終ジャッジ日時 2024-04-29 23:46:07
合計ジャッジ時間 24,779 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1,924 ms
244,864 KB
testcase_11 AC 714 ms
98,668 KB
testcase_12 AC 22 ms
8,192 KB
testcase_13 AC 1,658 ms
210,432 KB
testcase_14 AC 1,033 ms
136,952 KB
testcase_15 AC 1,101 ms
144,256 KB
testcase_16 AC 857 ms
112,256 KB
testcase_17 AC 430 ms
62,976 KB
testcase_18 AC 470 ms
67,584 KB
testcase_19 AC 1,064 ms
140,288 KB
testcase_20 AC 2,091 ms
268,160 KB
testcase_21 AC 2,116 ms
268,288 KB
testcase_22 AC 2,117 ms
268,076 KB
testcase_23 AC 2,164 ms
268,196 KB
testcase_24 AC 2,138 ms
268,192 KB
testcase_25 AC 2,146 ms
268,148 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<unordered_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++){
        unordered_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