結果

問題 No.368 LCM of K-products
ユーザー kurenai3110
提出日時 2016-12-15 22:35:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 89,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 14:53:11
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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