結果
問題 | No.811 約数の個数の最大化 |
ユーザー | tenten |
提出日時 | 2020-11-18 13:49:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 164 ms / 2,000 ms |
コード長 | 1,429 bytes |
コンパイル時間 | 2,419 ms |
コンパイル使用メモリ | 81,796 KB |
実行使用メモリ | 58,280 KB |
最終ジャッジ日時 | 2023-09-30 15:01:00 |
合計ジャッジ時間 | 5,578 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
55,664 KB |
testcase_01 | AC | 119 ms
53,756 KB |
testcase_02 | AC | 156 ms
56,208 KB |
testcase_03 | AC | 119 ms
55,888 KB |
testcase_04 | AC | 123 ms
55,956 KB |
testcase_05 | AC | 120 ms
56,064 KB |
testcase_06 | AC | 137 ms
55,724 KB |
testcase_07 | AC | 138 ms
56,328 KB |
testcase_08 | AC | 147 ms
55,740 KB |
testcase_09 | AC | 137 ms
58,280 KB |
testcase_10 | AC | 135 ms
55,700 KB |
testcase_11 | AC | 153 ms
56,144 KB |
testcase_12 | AC | 147 ms
56,764 KB |
testcase_13 | AC | 138 ms
56,148 KB |
testcase_14 | AC | 164 ms
58,224 KB |
ソースコード
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(); HashMap<Integer, Integer> inner = new HashMap<>(); int x = n; for (int i = 2; i <= Math.sqrt(n); i++) { while (x % i == 0) { inner.put(i, inner.getOrDefault(i, 0) + 1); x /= i; } } if (x > 1) { inner.put(x, inner.getOrDefault(x, 0) + 1); } int[] totals = new int[n]; int max = 0; int ans = 0; for (int i = 2; i < n; i++) { boolean flag = (totals[i] == 0); for (int j = 1; j * i < n; j++) { totals[i * j]++; } if (max < totals[i]) { if (getCount(i, inner) >= k) { max = totals[i]; ans = i; } } } System.out.println(ans); } static int getCount(int x, HashMap<Integer, Integer> inner) { int count = 0; for (int y : inner.keySet()) { for (int i = 0; i < inner.get(y); i++) { if (x % y == 0) { count++; x /= y; } else { break; } } } return count; } }