結果

問題 No.368 LCM of K-products
ユーザー PachicobuePachicobue
提出日時 2017-12-31 22:22:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,774 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 215,304 KB
実行使用メモリ 17,108 KB
最終ジャッジ日時 2023-08-23 12:44:08
合計ジャッジ時間 6,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
5,340 KB
testcase_01 AC 139 ms
16,932 KB
testcase_02 AC 140 ms
17,108 KB
testcase_03 AC 152 ms
16,948 KB
testcase_04 AC 152 ms
17,068 KB
testcase_05 AC 149 ms
17,060 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 72 ms
7,128 KB
testcase_14 AC 147 ms
10,052 KB
testcase_15 AC 156 ms
17,048 KB
testcase_16 AC 100 ms
6,984 KB
testcase_17 AC 68 ms
5,360 KB
testcase_18 AC 175 ms
10,400 KB
testcase_19 AC 27 ms
4,780 KB
testcase_20 AC 77 ms
7,240 KB
testcase_21 AC 17 ms
4,400 KB
testcase_22 AC 159 ms
10,460 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 167 ms
10,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
ll power(const ll p, const int n)
{
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return (power(p, n - 1) * p) % MOD;
    } else {
        const ll pp = power(p, n / 2);
        return (pp * pp) % MOD;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    constexpr ll SQRT = 31623;
    vector<bool> isprime(SQRT, true);
    vector<ll> prime;
    for (ll i = 2; i < SQRT; i++) {
        if (isprime[i]) {
            for (ll j = 2; i * j < SQRT; j++) {
                isprime[i * j] = false;
            }
        }
    }
    for (ll i = 2; i < SQRT; i++) {
        if (isprime[i]) {
            prime.push_back(i);
        }
    }
    const int size = prime.size();
    vector<priority_queue<int, vector<int>, greater<int>>> ind(size);
    map<ll, int> rest;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        for (int j = 0; j < size; j++) {
            const ll p = prime[j];
            int cnt = 0;
            while (a % p == 0) {
                a /= p;
                cnt++;
            }
            ind[j].push(cnt);
            if (ind[j].size() == K + 1) {
                ind[j].pop();
            }
        }
        if (a > 1) {
            rest[a]++;
        }
    }

    ll ans = 1;
    for (int i = 0; i < size; i++) {
        int sum = 0;
        for (int j = 0; j < K; j++) {
            sum += ind[i].top();
            ind[i].pop();
        }
        ans *= power(prime[i], sum);
        ans %= MOD;
    }
    for (const auto& e : rest) {
        ans *= power(e.first, e.second);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}
0