結果
| 問題 |
No.368 LCM of K-products
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2016-04-29 23:17:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 908 bytes |
| コンパイル時間 | 1,745 ms |
| コンパイル使用メモリ | 181,124 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 14:42:55 |
| 合計ジャッジ時間 | 3,016 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
/*
* Problem link
*
*/
#include<bits/stdc++.h>
using namespace std;
struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init;
typedef long long LL;
const LL MOD = (LL)1e9 + 7;
int main() {
#ifdef INPUT_FROM_FILE
ifstream cin("sample.in");
ofstream cout("sample.out");
#endif
map<int, vector<int>> m;
int N,K;
cin >> N >> K;
vector<int> v(N);
for (auto& it : v)cin >> it;
for (auto& it : v) {
for (int i = 2; i*i <= it; i++) {
if (it%i == 0) {
int cnt = 0;
while (it%i == 0) { cnt++, it /= i; }
//cout << i << " " << cnt << endl;
m[i].push_back(cnt);
}
}
if (it != 1)m[it].push_back(1);
}
LL res = 1;
for (auto& u : m) {
auto& p = u.second;
sort(p.begin(),p.end());
reverse(p.begin(), p.end());
for (int i = 0; i < min((int)p.size(),K); i++)
for (int j = 0; j < p[i]; j++)
(res *= u.first) %= MOD;
}
cout << res << endl;
return 0;
}
btk