結果

問題 No.368 LCM of K-products
ユーザー pekempeypekempey
提出日時 2016-04-29 22:52:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 178,468 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:08:49
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
4,348 KB
testcase_01 AC 93 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 30 ms
4,348 KB
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 328 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 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 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 33 ms
4,348 KB
testcase_15 AC 37 ms
4,348 KB
testcase_16 AC 30 ms
4,348 KB
testcase_17 AC 27 ms
4,348 KB
testcase_18 AC 38 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 27 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 36 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 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 14 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 7;

map<long long, long long> primeFactors(long long n) {
	map<long long, long long> ret;
	for (long long i = 2; i * i <= n; i++)
		while (n % i == 0) ret[i]++, n /= i;
	if (n != 1) ret[n]++;
	return ret;
}

long long modpow(long long a, long long b, long long mod) {
	long long result = 1;
	for (; b > 0; a = a * a % mod, b /= 2) if (b & 1) result = result * a % mod;
	return result;
}

int main() {
	map<long long, vector<long long>> mp;
	int n, K;
	cin >> n >> K;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (auto p : primeFactors(a)) {
			mp[p.first].push_back(p.second);
		}

	}

	long long ans = 1;
	for (auto p : mp) {
		sort(p.second.rbegin(), p.second.rend());
		int sum = 0;
		for (int i = 0; i < min<int>(p.second.size(), K); i++) {
			sum += p.second[i];
		}
		(ans *= modpow(p.first, sum, mod)) %= mod;
	}
	cout << ans << endl;
}
0