結果

問題 No.368 LCM of K-products
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-26 23:33:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 79,524 KB
実行使用メモリ 111,400 KB
最終ジャッジ日時 2024-04-26 03:58:36
合計ジャッジ時間 17,080 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 671 ms
110,192 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 143 ms
54,164 KB
testcase_07 WA -
testcase_08 AC 162 ms
54,584 KB
testcase_09 AC 163 ms
54,304 KB
testcase_10 AC 158 ms
53,972 KB
testcase_11 AC 134 ms
53,284 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 146 ms
54,176 KB
testcase_24 AC 136 ms
53,196 KB
testcase_25 AC 163 ms
54,368 KB
testcase_26 AC 148 ms
54,172 KB
testcase_27 AC 163 ms
56,652 KB
testcase_28 AC 146 ms
53,836 KB
testcase_29 AC 164 ms
54,624 KB
testcase_30 AC 156 ms
56,760 KB
testcase_31 AC 161 ms
56,420 KB
testcase_32 AC 168 ms
56,492 KB
testcase_33 WA -
testcase_34 AC 603 ms
110,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int M = (int)Math.pow(10, 4);
    ArrayList<Integer> prime = new ArrayList<Integer>();
    boolean[] is_prime = new boolean[M + 1];
    for(int i = 0; i <= M; i++) is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    for(int i = 2; i <= M; i++) {
      if(is_prime[i]) {
        prime.add(i);
        for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
      }
    }
    int t = prime.size();
    int[][] rui = new int[n][t];
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      for(int j = 0; j < t; j++) {
        int p = prime.get(j);
        while(a % p == 0) {
          a /= p;
          rui[i][j]++;
        }
      }
    }
    long ans = 1;
    long MOD = (long)Math.pow(10, 9) + 7;
    for(int j = 0; j < t; j++) {
      int[] r = new int[n];
      for(int i = 0; i < n; i++) {
        r[i] = rui[i][j];
      }
      Arrays.sort(r);
      int p = prime.get(j);
      for(int l = n - 1; l >= n - k; l--) {
        ans = (ans * (long)Math.pow(p, r[l])) % MOD;
      }
    }
    System.out.println(ans);
  }
}
0