結果
問題 | No.1809 Divide NCK |
ユーザー | tenten |
提出日時 | 2023-07-20 09:49:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 2,730 bytes |
コンパイル時間 | 5,176 ms |
コンパイル使用メモリ | 87,628 KB |
実行使用メモリ | 51,744 KB |
最終ジャッジ日時 | 2024-09-20 06:36:59 |
合計ジャッジ時間 | 6,837 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
50,312 KB |
testcase_01 | AC | 52 ms
50,268 KB |
testcase_02 | AC | 50 ms
50,440 KB |
testcase_03 | AC | 50 ms
50,496 KB |
testcase_04 | AC | 50 ms
50,388 KB |
testcase_05 | AC | 50 ms
50,060 KB |
testcase_06 | AC | 52 ms
50,056 KB |
testcase_07 | AC | 53 ms
50,256 KB |
testcase_08 | AC | 54 ms
50,372 KB |
testcase_09 | AC | 53 ms
50,420 KB |
testcase_10 | AC | 53 ms
50,300 KB |
testcase_11 | AC | 52 ms
50,392 KB |
testcase_12 | AC | 52 ms
50,368 KB |
testcase_13 | AC | 51 ms
50,296 KB |
testcase_14 | AC | 52 ms
49,932 KB |
testcase_15 | AC | 52 ms
50,364 KB |
testcase_16 | AC | 75 ms
51,160 KB |
testcase_17 | AC | 52 ms
50,376 KB |
testcase_18 | AC | 73 ms
51,336 KB |
testcase_19 | AC | 73 ms
51,464 KB |
testcase_20 | AC | 51 ms
50,376 KB |
testcase_21 | AC | 52 ms
49,936 KB |
testcase_22 | AC | 52 ms
50,316 KB |
testcase_23 | AC | 51 ms
50,352 KB |
testcase_24 | AC | 52 ms
50,264 KB |
testcase_25 | AC | 51 ms
50,304 KB |
testcase_26 | AC | 51 ms
50,008 KB |
testcase_27 | AC | 52 ms
50,364 KB |
testcase_28 | AC | 52 ms
50,372 KB |
testcase_29 | AC | 72 ms
51,744 KB |
testcase_30 | AC | 53 ms
50,084 KB |
testcase_31 | AC | 49 ms
50,312 KB |
testcase_32 | AC | 51 ms
49,956 KB |
testcase_33 | AC | 55 ms
49,892 KB |
testcase_34 | AC | 51 ms
50,044 KB |
testcase_35 | AC | 53 ms
50,460 KB |
testcase_36 | AC | 51 ms
50,392 KB |
testcase_37 | AC | 52 ms
50,316 KB |
testcase_38 | AC | 52 ms
50,484 KB |
testcase_39 | AC | 51 ms
50,440 KB |
testcase_40 | AC | 52 ms
50,240 KB |
testcase_41 | AC | 49 ms
50,384 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); long k = sc.nextLong(); long m = sc.nextLong(); HashMap<Long, Integer> contents = new HashMap<>(); for (long i = 2; i <= Math.sqrt(m); i++) { while (m % i == 0) { contents.put(i, contents.getOrDefault(i, 0) + 1); m /= i; } } if (m > 1) { contents.put(m, 1); } HashMap<Long, Long> child = getMap(n, contents); HashMap<Long, Long> mother = getMap(k, contents); HashMap<Long, Long> father = getMap(n - k, contents); long ans = Long.MAX_VALUE; for (long x : contents.keySet()) { ans = Math.min(ans, (child.get(x) - mother.get(x) - father.get(x)) / contents.get(x)); } System.out.println(ans); } static HashMap<Long, Long> getMap(long value, HashMap<Long, Integer> base) { HashMap<Long, Long> ans = new HashMap<>(); for (long x : base.keySet()) { long current = x; long count = 0; while (true) { count += value / current; if (value / x < current) { break; } current *= x; } ans.put(x, count); } return ans; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }