結果
問題 |
No.1529 Constant Lcm
|
ユーザー |
![]() |
提出日時 | 2021-12-17 08:03:03 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 943 ms / 3,000 ms |
コード長 | 1,900 bytes |
コンパイル時間 | 3,462 ms |
コンパイル使用メモリ | 146,272 KB |
実行使用メモリ | 40,020 KB |
最終ジャッジ日時 | 2024-09-14 08:04:44 |
合計ジャッジ時間 | 13,836 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <string.h> #include <vector> using namespace std; typedef long long ll; const ll MOD = 998244353; class Prime { public: vector<ll> prime_list; const ll MAX_N = 1000000; Prime() { bool checked[MAX_N + 1]; memset(checked, false, sizeof(checked)); for (ll i = 2; i <= MAX_N; ++i) { if (!checked[i]) { prime_list.push_back(i); for (ll j = i * i; j <= MAX_N; j += i) { checked[j] = true; } } } } map<ll, int> prime_division(ll n) { map<ll, int> res; for (ll i = 0; prime_list[i] <= sqrt(n); ++i) { ll p = prime_list[i]; while (n % p == 0) { res[p]++; n /= p; } } if (n != 1) { res[n] = 1; } return res; } bool is_prime(ll n) { if (n <= 1) return false; for (int i = 0; i < prime_list.size(); ++i) { if (n % prime_list[i]) return false; } return true; } }; int main() { ll N; cin >> N; Prime prime; vector<int> counter(N + 1, 0); map<ll, bool> checked; for (ll i = 1; i <= N - 1; ++i) { ll a = i * (N - i); if (checked[a]) continue; checked[a] = true; map<ll, int> res1 = prime.prime_division(i); map<ll, int> res2 = prime.prime_division(N - i); map<ll, int> res; for (auto e : res1) { res[e.first] += e.second; } for (auto e : res2) { res[e.first] += e.second; } for (auto e : res) { counter[e.first] = max(counter[e.first], e.second); } } ll ans = 1; for (ll i = 1; i < N; ++i) { if (counter[i] == 0) continue; ll p = 1; for (int j = 0; j < counter[i]; ++j) { p *= i; p %= MOD; } ans *= p; ans %= MOD; } cout << ans << endl; return 0; }