結果
問題 | No.1529 Constant Lcm |
ユーザー | H3PO4 |
提出日時 | 2023-03-14 10:27:02 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,340 ms / 3,000 ms |
コード長 | 1,882 bytes |
コンパイル時間 | 935 ms |
コンパイル使用メモリ | 91,940 KB |
実行使用メモリ | 259,768 KB |
最終ジャッジ日時 | 2023-10-18 11:31:13 |
合計ジャッジ時間 | 25,359 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 4 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 1 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2,047 ms
237,212 KB |
testcase_11 | AC | 737 ms
95,888 KB |
testcase_12 | AC | 24 ms
8,100 KB |
testcase_13 | AC | 1,659 ms
204,060 KB |
testcase_14 | AC | 997 ms
133,408 KB |
testcase_15 | AC | 1,097 ms
140,576 KB |
testcase_16 | AC | 848 ms
108,932 KB |
testcase_17 | AC | 440 ms
61,184 KB |
testcase_18 | AC | 464 ms
66,104 KB |
testcase_19 | AC | 1,058 ms
136,812 KB |
testcase_20 | AC | 2,223 ms
259,768 KB |
testcase_21 | AC | 2,221 ms
259,744 KB |
testcase_22 | AC | 2,340 ms
259,760 KB |
testcase_23 | AC | 2,234 ms
259,768 KB |
testcase_24 | AC | 2,228 ms
259,744 KB |
testcase_25 | AC | 2,214 ms
259,768 KB |
ソースコード
#include <iostream> #include <vector> #include <unordered_map> const int MOD = 998244353; long long pow(long long x, long long n) { long long res = 1; while (n > 0) { if (n & 1) { res = res * x % MOD; } x = x * x % MOD; n >>= 1; } return res; } std::vector<std::unordered_map<int, int>> generate_factor_table(int &N) { std::vector<std::unordered_map<int, int>> table(N + 1); for (int i = 2; i < N + 1; i++) { if (table.at(i).empty()) { // i is prime for (int j = i; j < N + 1; j += i) { int x = j; int ct = 0; while (x % i == 0) { x /= i; ct += 1; } table.at(j).emplace(i, ct); } } } return table; } int main() { int N; std::cin >> N; auto table = generate_factor_table(N); std::unordered_map<int, int> lcm_dict; for (int x = 1; x < N; x++) { int y = N - x; std::unordered_map<int, int> ct; for (const auto &[k, v]: table.at(x)) { if (ct.find(k) == ct.end()) { ct.emplace(k, v); } else { ct.at(k) += v; } } for (const auto &[k, v]: table.at(y)) { if (ct.find(k) == ct.end()) { ct.emplace(k, v); } else { ct.at(k) += v; } } for (const auto &[k, v]: ct) { if (lcm_dict.find(k) == lcm_dict.end()) { lcm_dict.emplace(k, v); } else { if (lcm_dict.at(k) < v) { lcm_dict.at(k) = v; } } } } long long ans = 1; for (const auto &[k, v]: lcm_dict) { ans *= pow(k, v); ans %= MOD; } std::cout << ans << std::endl; }