結果

問題 No.368 LCM of K-products
ユーザー Im_GimletIm_Gimlet
提出日時 2020-07-28 22:09:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 190,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 06:49:11
合計ジャッジ時間 6,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
4,376 KB
testcase_01 AC 100 ms
4,376 KB
testcase_02 AC 241 ms
4,376 KB
testcase_03 AC 168 ms
4,376 KB
testcase_04 AC 153 ms
4,376 KB
testcase_05 AC 328 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 116 ms
4,380 KB
testcase_14 AC 176 ms
4,376 KB
testcase_15 AC 195 ms
4,376 KB
testcase_16 AC 170 ms
4,376 KB
testcase_17 AC 145 ms
4,376 KB
testcase_18 AC 201 ms
4,380 KB
testcase_19 AC 52 ms
4,380 KB
testcase_20 AC 136 ms
4,380 KB
testcase_21 AC 33 ms
4,384 KB
testcase_22 AC 196 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 78 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll mod = 1000000007;
int n, k;

int main() {
    cin >> n >> k;
    vector<ll> Avec(n, 0);
    for(int i = 0; i < n; ++i) cin >> Avec[i];
    sort(Avec.begin(), Avec.end());
    
    vector< map<ll, ll> > divisor(n, map<ll, ll>());
    for(int i = 0; i < n; ++i) {
        ll check = Avec[i];
        ll limit = sqrt(check) + 1;
        for(int j = 2; j < limit; ++j) {
            if(Avec[i] % j == 0) {
                while(1) {
                    if(Avec[i]%j == 0) {
                        divisor[i][j]++;
                        Avec[i] /= j;
                    }else break;
                }
            }
        }
        if(Avec[i] != 1) divisor[i][Avec[i]]++;
    }

    map<ll, vector<ll> > mcnt;
    ll ans = 1LL;
    for(int i = 0; i < n; ++i) {
        for(auto x : divisor[i]) {
            mcnt[x.first].emplace_back(x.second);
        }
    }

    for(auto x : mcnt) {
        sort(x.second.begin(), x.second.end(), greater<ll>());
        int cnt = 0;
        for(int i = 0; i < min(k, (int)x.second.size()); ++i) cnt += x.second[i];
        for(int i = 0; i < cnt; ++i) {
            ans *= x.first;
            ans %= mod;
        }
    }
    cout << ans << endl;
}
0