結果
問題 | No.368 LCM of K-products |
ユーザー | Grenache |
提出日時 | 2016-05-28 13:05:48 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 599 ms / 2,000 ms |
コード長 | 4,010 bytes |
コンパイル時間 | 3,990 ms |
コンパイル使用メモリ | 80,740 KB |
実行使用メモリ | 91,212 KB |
最終ジャッジ日時 | 2024-09-22 14:49:15 |
合計ジャッジ時間 | 14,510 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 462 ms
74,924 KB |
testcase_01 | AC | 362 ms
68,928 KB |
testcase_02 | AC | 474 ms
81,848 KB |
testcase_03 | AC | 430 ms
73,460 KB |
testcase_04 | AC | 571 ms
74,320 KB |
testcase_05 | AC | 599 ms
91,212 KB |
testcase_06 | AC | 90 ms
51,192 KB |
testcase_07 | AC | 89 ms
51,644 KB |
testcase_08 | AC | 79 ms
51,140 KB |
testcase_09 | AC | 77 ms
51,324 KB |
testcase_10 | AC | 77 ms
51,128 KB |
testcase_11 | AC | 77 ms
51,352 KB |
testcase_12 | AC | 91 ms
51,140 KB |
testcase_13 | AC | 476 ms
69,648 KB |
testcase_14 | AC | 452 ms
75,484 KB |
testcase_15 | AC | 515 ms
79,664 KB |
testcase_16 | AC | 467 ms
73,652 KB |
testcase_17 | AC | 447 ms
73,860 KB |
testcase_18 | AC | 485 ms
78,660 KB |
testcase_19 | AC | 307 ms
64,768 KB |
testcase_20 | AC | 401 ms
71,796 KB |
testcase_21 | AC | 234 ms
61,416 KB |
testcase_22 | AC | 591 ms
79,416 KB |
testcase_23 | AC | 79 ms
51,372 KB |
testcase_24 | AC | 79 ms
50,956 KB |
testcase_25 | AC | 76 ms
51,372 KB |
testcase_26 | AC | 79 ms
51,200 KB |
testcase_27 | AC | 78 ms
51,044 KB |
testcase_28 | AC | 78 ms
51,340 KB |
testcase_29 | AC | 76 ms
51,144 KB |
testcase_30 | AC | 75 ms
51,380 KB |
testcase_31 | AC | 78 ms
51,348 KB |
testcase_32 | AC | 77 ms
51,344 KB |
testcase_33 | AC | 327 ms
67,412 KB |
testcase_34 | AC | 105 ms
52,380 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.Map.*; public class Main_yukicoder368 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); Prime p = new Prime(100_000); List<Integer> primes = p.getPrimeList(100_000); int n = sc.nextInt(); int k = sc.nextInt(); Map<Integer, List<Integer>> hm = new HashMap<>(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); int tmp = a; for (int j : primes) { if (j * j > a) { break; } int cnt = 0; while (tmp % j == 0) { cnt++; tmp /= j; } if (hm.containsKey(j)) { hm.get(j).add(cnt); } else { List<Integer> ltmp = new ArrayList<>(); ltmp.add(cnt); hm.put(j, ltmp); } } if (tmp != 1) { if (hm.containsKey(tmp)) { hm.get(tmp).add(1); } else { List<Integer> ltmp = new ArrayList<>(); ltmp.add(1); hm.put(tmp, ltmp); } } } final long MOD = 1_000_000_007; long ret = 1; for (Entry<Integer, List<Integer>> e : hm.entrySet()) { List<Integer> bp = e.getValue(); Collections.sort(bp); int pp = 0; for (int i = bp.size() - 1; bp.size() - i <= k && i >= 0; i--) { pp += bp.get(i); } ret = ret * pow(e.getKey(), pp, MOD) % MOD; } pr.println(ret); pr.close(); sc.close(); } private static long pow(int a, int n, long MOD) { int loop = n; long ret = 1; long x = a; while (loop > 0) { if (loop % 2 == 1) { ret = ret * x % MOD; } x = x * x % MOD; loop /= 2; } return ret; } @SuppressWarnings("unused") private static class Prime { private int n; private List<Integer> primes; private BitSet p; Prime(int n) { this.n = n; p = new BitSet(n / 2); int m = (int)Math.sqrt(n); for (int i = 1; i <= m; i++) { if (p.get(i - 1)) { continue; } for (int j = 2 * i * (i + 1); 2 * j + 1 <= n; j += 2 * i + 1) { p.set(j - 1); } } } boolean isPrime(int n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } return !p.get(n / 2 - 1); } List<Integer> getPrimeList(int n) { if (primes != null) { return primes; } primes = new ArrayList<>(); primes.add(2); for (int i = 1; 2 * i + 1 <= n; i++) { if (!p.get(i - 1)) { primes.add(2 * i + 1); } } return primes; } private static boolean isPrime(long n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }