結果
| 問題 |
No.368 LCM of K-products
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-27 19:55:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 410 ms / 2,000 ms |
| コード長 | 1,429 bytes |
| コンパイル時間 | 2,993 ms |
| コンパイル使用メモリ | 79,316 KB |
| 実行使用メモリ | 59,088 KB |
| 最終ジャッジ日時 | 2024-07-21 22:01:27 |
| 合計ジャッジ時間 | 10,744 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
HashMap<Integer, ArrayList<Integer>> result = new HashMap<>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
for (int j = 2; j <= Math.sqrt(x); j++) {
int count = 0;
while (x % j == 0) {
count++;
x /= j;
}
if (count > 0) {
if (!result.containsKey(j)) {
result.put(j, new ArrayList<>());
}
result.get(j).add(count);
}
}
if (x > 1) {
if (!result.containsKey(x)) {
result.put(x, new ArrayList<>());
}
result.get(x).add(1);
}
}
long ans = 1;
for (int x : result.keySet()) {
Collections.sort(result.get(x));
for (int i = 0; i < result.get(x).size() && i < k; i++) {
for (int j = 0; j < result.get(x).get(result.get(x).size() - i - 1); j++) {
ans *= x;
ans %= MOD;
}
}
}
System.out.println(ans);
}
}
tenten