結果
問題 | No.1529 Constant Lcm |
ユーザー |
![]() |
提出日時 | 2021-06-04 20:57:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 773 ms / 3,000 ms |
コード長 | 2,048 bytes |
コンパイル時間 | 1,610 ms |
コンパイル使用メモリ | 179,916 KB |
実行使用メモリ | 106,028 KB |
最終ジャッジ日時 | 2024-11-19 10:41:59 |
合計ジャッジ時間 | 9,719 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;using pll = pair<ll, ll>;using tlll = tuple<ll, ll, ll>;//constexpr ll MOD = 1e9 + 7;constexpr ll MOD = 998244353;//constexpr ll MOD = ;ll mod(ll A, ll M) {return (A % M + M) % M;}constexpr ll INF = 1LL << 60;template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)class prime{public:vector<bool> isprime;vector<ll> P;vector<vector<pll>> fac;prime(ll N){isprime = vector<bool>(N + 1, true);isprime.at(0) = false, isprime.at(1) = false;for (ll n = 2; n <= N; n++){if (isprime.at(n)){P.push_back(n);for (ll k = 2; k * n <= N; k++){isprime.at(k * n) = false;}}}fac = vector<vector<pll>>(N + 1);for (auto p : P){for (ll k = 1; k * p <= N; k++){fac.at(k * p).push_back(make_pair(p, 1));}for (ll tmp = p * p; tmp <= N; tmp *= p){for (ll k = 1; k * tmp <= N; k++){fac.at(k * tmp).back().second++;}}}}};int main(){ll N;cin >> N;prime pr(N - 1);ll ans = 1;vector<ll> T(N);for (auto p : pr.P){ll tmp = 1;if (N % p == 0){fill(T.begin(), T.end(), 1);for (ll i = 1; i <= N - 1; i++){ll ii = i;while (ii % p == 0){ii /= p;T.at(i) *= p;}}for (ll i = 1; i <= N - 1; i++){chmax(tmp, T.at(i) * T.at(N - i));}ans *= tmp % MOD;ans %= MOD;}else{while (tmp * p <= N){tmp *= p;}ans *= tmp % MOD;ans %= MOD;}//cerr << tmp << endl;}cout << ans << endl;}