結果
問題 | No.368 LCM of K-products |
ユーザー | tenten |
提出日時 | 2023-12-13 19:23:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 292 ms / 2,000 ms |
コード長 | 2,879 bytes |
コンパイル時間 | 2,715 ms |
コンパイル使用メモリ | 96,332 KB |
実行使用メモリ | 61,328 KB |
最終ジャッジ日時 | 2023-12-13 19:23:59 |
合計ジャッジ時間 | 8,659 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 170 ms
58,620 KB |
testcase_01 | AC | 258 ms
61,328 KB |
testcase_02 | AC | 104 ms
55,664 KB |
testcase_03 | AC | 168 ms
58,620 KB |
testcase_04 | AC | 141 ms
58,340 KB |
testcase_05 | AC | 292 ms
58,956 KB |
testcase_06 | AC | 55 ms
53,992 KB |
testcase_07 | AC | 55 ms
53,948 KB |
testcase_08 | AC | 55 ms
53,996 KB |
testcase_09 | AC | 56 ms
53,992 KB |
testcase_10 | AC | 55 ms
53,980 KB |
testcase_11 | AC | 57 ms
53,988 KB |
testcase_12 | AC | 58 ms
54,000 KB |
testcase_13 | AC | 158 ms
57,652 KB |
testcase_14 | AC | 209 ms
59,176 KB |
testcase_15 | AC | 218 ms
59,404 KB |
testcase_16 | AC | 162 ms
58,708 KB |
testcase_17 | AC | 164 ms
58,564 KB |
testcase_18 | AC | 218 ms
58,644 KB |
testcase_19 | AC | 115 ms
56,584 KB |
testcase_20 | AC | 192 ms
58,156 KB |
testcase_21 | AC | 110 ms
56,404 KB |
testcase_22 | AC | 181 ms
59,004 KB |
testcase_23 | AC | 56 ms
53,972 KB |
testcase_24 | AC | 56 ms
54,000 KB |
testcase_25 | AC | 55 ms
53,992 KB |
testcase_26 | AC | 54 ms
53,996 KB |
testcase_27 | AC | 54 ms
53,972 KB |
testcase_28 | AC | 56 ms
53,980 KB |
testcase_29 | AC | 55 ms
53,992 KB |
testcase_30 | AC | 54 ms
54,000 KB |
testcase_31 | AC | 55 ms
53,988 KB |
testcase_32 | AC | 55 ms
53,984 KB |
testcase_33 | AC | 136 ms
57,376 KB |
testcase_34 | AC | 103 ms
53,632 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); HashMap<Integer, ArrayList<Integer>> allCount = new HashMap<>(); while (n-- > 0) { int x = sc.nextInt(); HashMap<Integer, Integer> counts = new HashMap<>(); for (int i = 2; i <= Math.sqrt(x); i++) { while (x % i == 0) { counts.put(i, counts.getOrDefault(i, 0) + 1); x /= i; } } if (x > 1) { counts.put(x, 1); } for (int y : counts.keySet()) { if (!allCount.containsKey(y)) { allCount.put(y, new ArrayList<>()); } allCount.get(y).add(counts.get(y)); } } long ans = 1; for (int x : allCount.keySet()) { Collections.sort(allCount.get(x)); int sum = 0; for (int i = 0; i < k && i < allCount.get(x).size(); i++) { sum += allCount.get(x).get(allCount.get(x).size() - i - 1); } ans *= pow(x, sum); ans %= MOD; } System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }