結果

問題 No.368 LCM of K-products
ユーザー h_nosonh_noson
提出日時 2016-04-30 01:27:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:12:06
合計ジャッジ時間 2,113 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,348 KB
testcase_01 AC 33 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 11 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 110 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 12 ms
4,348 KB
testcase_17 AC 11 ms
4,348 KB
testcase_18 AC 14 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
#define MOD 1000000007

typedef long long ll;

ll power(ll x, int n) {
    ll ret = 1; while (n > 0) { if (n % 2) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        n /= 2;
    }
    return ret;
}

void get_factors(int n, map<int,int>& m) {
    int i;
    i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            m[i]++;
            n /= i;
        }
        else
            i++;
    }
    m[n]++;
}

int main() {
    int i, j, n, k;
    ll ans;
    map<int,vector<int>> factors;
    cin >> n >> k;
    rep (i,n) {
        int a;
        map<int,int> m;
        cin >> a;
        get_factors(a,m);
        for (auto&& p : m)
            factors[p.first].push_back(p.second);
    }
    ans = 1;
    for (auto&& m : factors) {
        int sum = 0;
        sort(m.second.begin(),m.second.end(),greater<int>{});
        rep (i,min(k,(int)m.second.size())) sum += m.second[i];
        ans *= power(m.first,sum);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0