結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-06 23:53:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,592 ms / 3,000 ms |
| コード長 | 2,146 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 178,320 KB |
| 実行使用メモリ | 16,004 KB |
| 最終ジャッジ日時 | 2024-07-01 12:17:00 |
| 合計ジャッジ時間 | 18,665 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 998244353;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}
ll modpow(ll a, ll n) {
if(n == 0) return 1;
auto t = modpow(a,n/2);
t = t*t;
t %= MOD;
if(n & 1) {
t *= a;
t %= MOD;
}
return t;
}
template <typename T>
struct PrimeFact {
vector<T> spf;
PrimeFact(T N) { init(N); }
void init(T N) { // 前処理。spf を求める
spf.assign(N + 1, 0);
for (T i = 0; i <= N; i++) spf[i] = i;
for (T i = 2; i * i <= N; i++) {
if (spf[i] == i) {
for (T j = i * i; j <= N; j += i) {
if (spf[j] == j) {
spf[j] = i;
}
}
}
}
}
map<T, T> get(T n) { // nの素因数分解を求める
map<T, T> m;
while (n != 1) {
m[spf[n]]++;
n /= spf[n];
}
return m;
}
};
int main() {
ll N; cin >> N;
map<ll,ll> LCM;
PrimeFact<ll> fp(1000010);
for(ll i = 1; i <= N-1; i++) {
map<ll,ll> mp;
for(auto e : fp.get(i)) mp[e.first] += e.second;
for(auto e : fp.get(N-i)) mp[e.first] += e.second;
for(auto e : mp) {
//cout << e.first << " " << e.second << endl;
LCM[e.first] = max(LCM[e.first],e.second);
}
}
ll ans = 1;
for(auto e : LCM) {
ans *= modpow(e.first, e.second);
ans %= MOD;
}
cout << ans << endl;
return 0;
}