結果

問題 No.1529 Constant Lcm
ユーザー rogi52rogi52
提出日時 2021-06-04 20:31:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,395 ms / 3,000 ms
コード長 1,369 bytes
コンパイル時間 3,156 ms
コンパイル使用メモリ 177,572 KB
実行使用メモリ 10,792 KB
最終ジャッジ日時 2023-08-12 09:39:42
合計ジャッジ時間 17,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,952 KB
testcase_01 AC 11 ms
7,188 KB
testcase_02 AC 9 ms
7,180 KB
testcase_03 AC 9 ms
6,952 KB
testcase_04 AC 9 ms
7,032 KB
testcase_05 AC 10 ms
6,992 KB
testcase_06 AC 9 ms
6,948 KB
testcase_07 AC 9 ms
6,896 KB
testcase_08 AC 9 ms
6,900 KB
testcase_09 AC 9 ms
7,012 KB
testcase_10 AC 1,229 ms
10,372 KB
testcase_11 AC 442 ms
8,340 KB
testcase_12 AC 27 ms
7,224 KB
testcase_13 AC 1,030 ms
9,904 KB
testcase_14 AC 607 ms
9,260 KB
testcase_15 AC 691 ms
9,116 KB
testcase_16 AC 533 ms
8,520 KB
testcase_17 AC 277 ms
8,056 KB
testcase_18 AC 303 ms
8,012 KB
testcase_19 AC 649 ms
9,104 KB
testcase_20 AC 1,387 ms
10,692 KB
testcase_21 AC 1,367 ms
10,708 KB
testcase_22 AC 1,374 ms
10,792 KB
testcase_23 AC 1,395 ms
10,584 KB
testcase_24 AC 1,384 ms
10,580 KB
testcase_25 AC 1,340 ms
10,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<int> smallest_prime_factors(int N){
   vector<int> spf(N + 1);
   iota(spf.begin(), spf.end(), 0);
   for(int i = 2; i * i <= N; i++){
       if(spf[i] != i) continue;
       for(int j = i * i; j <= N; j += i){
            if(spf[j] == j) spf[j] = i;
       }
   }
   return spf;
}

vector<int> prime_facrorize_query(int x, vector<int> &spf){
   vector<int> res;
   while(x != 1){ res.emplace_back(spf[x]); x /= spf[x]; }
   sort(res.begin(), res.end());
   return res;
}

ll mod = 998244353;
ll modpow(ll a,ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N; cin >> N;
    int MX = 1000000;
    auto spf = smallest_prime_factors(MX);
    
    map<int,int> cnt;
    for(int i = 1; i <= N - 1; i++){
        auto a = prime_facrorize_query(i, spf);
        auto b = prime_facrorize_query(N - i, spf);
        map<int,int> mp;
        for(int j : a) mp[j]++;
        for(int j : b) mp[j]++;
        for(auto e : mp) cnt[e.first] = max(cnt[e.first], e.second);
    }

    ll ans = 1;
    for(auto e : cnt) ans = (ans * modpow(e.first, e.second)) % mod;
    cout << ans << endl;
}
0