結果

問題 No.368 LCM of K-products
ユーザー kurenai3110kurenai3110
提出日時 2016-12-15 22:35:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 89,340 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:22:22
合計ジャッジ時間 2,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <functional>
using namespace std;
#define MOD (int)1e9+7

int main()
{
	int n, k; cin >> n >> k;
	map<long long, string>M;
	for (int i = 0; i < n; i++) {
		long long a; cin >> a;
		for (int j = 2; j*j <= a; j++) {
			int cnt = 0;
			while(!(a%j)) {
				cnt++;
				a /= j;
			}
			if(cnt)M[j] += to_string(cnt)+",";
		}
		if (a != 1)M[a] += to_string(1)+",";
	}

	long long sum = 1;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		long long prime = itr->first;
		string number = itr->second;

		int first = 0;

		vector<int>jou;
		for (int i = 0; i < number.size(); i++) {
			if (number[i] == ',') {
				jou.push_back(stoi(number.substr(first, i - first)));
				first = i + 1;
			}
		}

		sort(jou.begin(), jou.end(), greater<int>());

		for (int i = 0; i < k && i < jou.size(); i++) {
			sum *= (long long)pow(prime, jou[i]);
			sum %= MOD;
		}
	}

	cout << sum << endl;

    return 0;
}
0