結果

問題 No.368 LCM of K-products
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-27 20:04:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,308 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 79,336 KB
実行使用メモリ 52,640 KB
最終ジャッジ日時 2024-04-28 12:12:49
合計ジャッジ時間 8,794 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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();
    ArrayList<Integer> prime = new ArrayList<Integer>();
    int[] a = new int[n];
    HashSet<Integer> set = new HashSet<Integer>();
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      int t = a[i];
      for(int j = 2; j <= a[i]; j++) {
        if(t % j == 0) {
          set.add(j);
        }
        while(t % j == 0) {
          t /= j;
        }
      }
    }
    for(Iterator<Integer> i = set.iterator(); i.hasNext();) {
      prime.add(i.next());
    }
    int t = prime.size();
    int[][] rui = new int[n][t];
    for(int i = 0; i < n; i++) {
      int s = a[i];
      for(int j = 0; j < t; j++) {
        int p = prime.get(j);
        while(s % p == 0) {
          s /= 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