結果
問題 | No.1529 Constant Lcm |
ユーザー | sten_san |
提出日時 | 2021-06-04 20:34:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 753 ms / 3,000 ms |
コード長 | 2,566 bytes |
コンパイル時間 | 2,513 ms |
コンパイル使用メモリ | 211,804 KB |
最終ジャッジ日時 | 2025-01-21 22:12:26 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template <typename T, typename Compare = less<T>> T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); } template <typename T, typename Compare = less<T>> T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); } #include <atcoder/modint> using mint = atcoder::modint998244353; int main() { int n; cin >> n; auto sieve = vec<int>(uns, n + 1); iota(begin(sieve), end(sieve), 0); for (int i = 2; i <= n / i; ++i) { if (sieve[i] != i) { continue; } for (int j = i * i; j <= n; j += i) { if (sieve[j] == j) { sieve[j] = i; } } } auto p = vec<tuple<int, int>>(uns, n + 1, 0); for (int i = 2; i <= n; ++i) { auto &pf = p[i]; int x = i; while (x != 1) { int d = sieve[x]; int c = 0; while (x % d == 0) { ++c; x /= d; } pf.push_back({ d, c }); } } map<int, int> f; for (int i = 1; i <= n - 1; ++i) { auto iter1 = begin(p[i]); auto iter2 = begin(p[n - i]); while (iter1 != end(p[i]) && iter2 != end(p[n - i])) { auto [a1, b1] = *iter1; auto [a2, b2] = *iter2; if (a1 < a2) { chmax(f[a1], b1); ++iter1; continue; } if (a1 > a2) { chmax(f[a2], b2); ++iter2; continue; } chmax(f[a1], b1 + b2); ++iter1; ++iter2; } while (iter1 != end(p[i])) { chmax(f[get<0>(*iter1)], get<1>(*iter1)); ++iter1; } while (iter2 != end(p[n - i])) { chmax(f[get<0>(*iter2)], get<1>(*iter2)); ++iter2; } } mint ans = 1; for (auto [a, b] : f) { ans *= mint(a).pow(b); } cout << ans.val() << endl; }