結果

問題 No.368 LCM of K-products
ユーザー __math__math
提出日時 2016-05-18 22:28:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 3,379 ms
コンパイル使用メモリ 173,112 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-10-23 21:15:57
合計ジャッジ時間 2,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;

//素数列挙
bool prime[1000001]; //10^6
vector<int> prs;
void init_prime() {
	memset(prime, 1, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i < sizeof(prime); i++) if (prime[i])
		for (int j = i * 2; j < sizeof(prime); j += i) prime[j] = false;
	for (int i = 2; i < sizeof(prime); i++) if (prime[i]) prs.push_back(i);
}

int a[1000];

int main() {
	int n, k; cin >> n >> k;
	FOR(i, n) cin >> a[i];

	init_prime();
	map<int, vector<int>> mp;
	FOR(i, n) {
		int x = a[i];
		for (auto p : prs) {
			if (p * p > x) break;
			int cnt = 0;
			while (x % p == 0) {
				x /= p;
				cnt++;
			}
			if (cnt) mp[p].push_back(cnt);
		}
		if (x > 1) mp[x].push_back(1);
	}

	const int MOD = ten(9) + 7;
	ll ans = 1;
	for (auto& kv : mp) {
		auto& v = kv.second;
		sort(v.rbegin(), v.rend());
		int loop = min(k, sz(v));
		FOR(i, loop) {
			FOR(_, v[i]) ans = ans * kv.first % MOD;
		}
	}
	cout << ans << endl;

	return 0;
}
0