結果

問題 No.368 LCM of K-products
ユーザー Im_Gimlet
提出日時 2020-07-28 22:09:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 192,588 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 21:00:22
合計ジャッジ時間 5,365 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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