結果

問題 No.368 LCM of K-products
ユーザー kyunakyuna
提出日時 2019-08-18 00:45:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 1,319 ms
コンパイル使用メモリ 91,084 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 02:37:39
合計ジャッジ時間 3,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
4,348 KB
testcase_01 AC 97 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 31 ms
4,348 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 344 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 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 35 ms
4,348 KB
testcase_15 AC 38 ms
4,348 KB
testcase_16 AC 32 ms
4,348 KB
testcase_17 AC 29 ms
4,348 KB
testcase_18 AC 40 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 28 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 38 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 15 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0