結果
問題 | No.368 LCM of K-products |
ユーザー |
![]() |
提出日時 | 2019-08-18 00:45:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 332 ms / 2,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 1,060 ms |
コンパイル使用メモリ | 91,284 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-25 10:38:44 |
合計ジャッジ時間 | 2,888 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> #include <map> using namespace std; const int MOD = (int)1e9 + 7; map<long long, int> prime_factorize(long long n) { map<long long, int> res; for (long long p = 2; p * p <= n; ++p) { while (n % p == 0) { ++res[p]; n /= p; } } if (n != 1) res[n] = 1; return res; } int main() { int n, k; cin >> n >> k; map<long long, vector<int>> p_cnt; for (int i = 0; i < n; i++) { int a; cin >> a; for (auto &p: prime_factorize(a)) { p_cnt[p.first].emplace_back(p.second); } } long long ans = 1; for (auto &p: p_cnt) { auto &v = p.second; sort(v.begin(), v.end()); int sz = min(k, (int)v.size()); int cnt = 0; while (sz--) cnt += v.back(), v.pop_back(); while (cnt--) (ans *= p.first) %= MOD; } cout << ans << endl; return 0; }