結果
| 問題 | No.1529 Constant Lcm |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-04 20:31:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,421 ms / 3,000 ms |
| コード長 | 1,369 bytes |
| コンパイル時間 | 2,104 ms |
| コンパイル使用メモリ | 180,500 KB |
| 実行使用メモリ | 10,936 KB |
| 最終ジャッジ日時 | 2024-11-19 09:24:52 |
| 合計ジャッジ時間 | 17,056 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
#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;
}