結果
問題 | No.368 LCM of K-products |
ユーザー | htensai |
提出日時 | 2019-11-21 12:56:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 1,734 bytes |
コンパイル時間 | 2,631 ms |
コンパイル使用メモリ | 80,512 KB |
実行使用メモリ | 61,064 KB |
最終ジャッジ日時 | 2024-04-17 23:08:03 |
合計ジャッジ時間 | 9,499 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 247 ms
58,872 KB |
testcase_01 | AC | 351 ms
60,268 KB |
testcase_02 | AC | 190 ms
56,368 KB |
testcase_03 | AC | 255 ms
60,264 KB |
testcase_04 | AC | 215 ms
60,028 KB |
testcase_05 | AC | 375 ms
59,444 KB |
testcase_06 | AC | 121 ms
54,432 KB |
testcase_07 | AC | 121 ms
54,336 KB |
testcase_08 | AC | 125 ms
54,124 KB |
testcase_09 | AC | 113 ms
53,472 KB |
testcase_10 | AC | 126 ms
54,148 KB |
testcase_11 | AC | 117 ms
54,008 KB |
testcase_12 | AC | 114 ms
53,132 KB |
testcase_13 | AC | 222 ms
57,980 KB |
testcase_14 | AC | 261 ms
58,956 KB |
testcase_15 | AC | 247 ms
61,064 KB |
testcase_16 | AC | 239 ms
58,876 KB |
testcase_17 | AC | 228 ms
58,648 KB |
testcase_18 | AC | 259 ms
61,064 KB |
testcase_19 | AC | 180 ms
56,968 KB |
testcase_20 | AC | 228 ms
58,784 KB |
testcase_21 | AC | 165 ms
56,384 KB |
testcase_22 | AC | 268 ms
61,032 KB |
testcase_23 | AC | 110 ms
53,856 KB |
testcase_24 | AC | 102 ms
52,876 KB |
testcase_25 | AC | 112 ms
54,296 KB |
testcase_26 | AC | 105 ms
54,144 KB |
testcase_27 | AC | 109 ms
53,884 KB |
testcase_28 | AC | 110 ms
53,988 KB |
testcase_29 | AC | 119 ms
54,156 KB |
testcase_30 | AC | 120 ms
54,020 KB |
testcase_31 | AC | 117 ms
53,976 KB |
testcase_32 | AC | 100 ms
52,956 KB |
testcase_33 | AC | 195 ms
56,948 KB |
testcase_34 | AC | 174 ms
54,668 KB |
ソースコード
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>> allMap = new HashMap<>(); for (int i = 0; i < n; i++) { HashMap<Integer, Integer> map = new HashMap<>(); int x = sc.nextInt(); for (int j = 2; j <= Math.sqrt(x); j++) { while (x % j == 0) { if (map.containsKey(j)) { map.put(j, map.get(j) + 1); } else { map.put(j, 1); } x /= j; } } if (x != 1) { if (map.containsKey(x)) { map.put(x, map.get(x) + 1); } else { map.put(x, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (!allMap.containsKey(entry.getKey())) { allMap.put(entry.getKey(), new ArrayList<Integer>()); } allMap.get(entry.getKey()).add(entry.getValue()); } } long total = 1; for (Map.Entry<Integer, ArrayList<Integer>> entry : allMap.entrySet()) { ArrayList<Integer> list = entry.getValue(); Collections.sort(list); int sum = 0; for (int i = 0; i < list.size() && i < k; i++) { sum += list.get(list.size() - i - 1); } total *= pow(entry.getKey(), sum); total %= MOD; } System.out.println(total); } static long pow(int base, int power) { long ans = 1; for (int i = 0; i < power; i++) { ans *= base; ans %= MOD; } return ans; } }