結果

問題 No.368 LCM of K-products
ユーザー tentententen
提出日時 2020-10-27 19:55:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 3,453 ms
コンパイル使用メモリ 76,164 KB
実行使用メモリ 62,736 KB
最終ジャッジ日時 2023-09-29 03:23:38
合計ジャッジ時間 12,543 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
58,212 KB
testcase_01 AC 353 ms
62,648 KB
testcase_02 AC 219 ms
58,340 KB
testcase_03 AC 271 ms
57,844 KB
testcase_04 AC 245 ms
60,924 KB
testcase_05 AC 380 ms
60,400 KB
testcase_06 AC 130 ms
55,980 KB
testcase_07 AC 130 ms
55,756 KB
testcase_08 AC 129 ms
55,904 KB
testcase_09 AC 129 ms
55,944 KB
testcase_10 AC 128 ms
55,572 KB
testcase_11 AC 127 ms
55,876 KB
testcase_12 AC 129 ms
55,652 KB
testcase_13 AC 247 ms
58,096 KB
testcase_14 AC 277 ms
58,008 KB
testcase_15 AC 284 ms
62,736 KB
testcase_16 AC 268 ms
58,312 KB
testcase_17 AC 264 ms
58,768 KB
testcase_18 AC 289 ms
60,472 KB
testcase_19 AC 206 ms
58,380 KB
testcase_20 AC 258 ms
57,944 KB
testcase_21 AC 194 ms
58,132 KB
testcase_22 AC 287 ms
60,856 KB
testcase_23 AC 128 ms
55,784 KB
testcase_24 AC 127 ms
55,752 KB
testcase_25 AC 128 ms
55,680 KB
testcase_26 AC 128 ms
55,844 KB
testcase_27 AC 127 ms
55,520 KB
testcase_28 AC 127 ms
55,792 KB
testcase_29 AC 127 ms
55,652 KB
testcase_30 AC 129 ms
55,872 KB
testcase_31 AC 127 ms
55,732 KB
testcase_32 AC 129 ms
55,920 KB
testcase_33 AC 227 ms
56,276 KB
testcase_34 AC 207 ms
56,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
    }
}
0