結果
問題 | No.1809 Divide NCK |
ユーザー | tenten |
提出日時 | 2022-01-20 11:52:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,852 bytes |
コンパイル時間 | 2,043 ms |
コンパイル使用メモリ | 78,420 KB |
実行使用メモリ | 38,120 KB |
最終ジャッジ日時 | 2024-05-02 20:22:56 |
合計ジャッジ時間 | 5,091 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
36,532 KB |
testcase_01 | AC | 44 ms
37,060 KB |
testcase_02 | AC | 44 ms
36,412 KB |
testcase_03 | AC | 46 ms
36,748 KB |
testcase_04 | AC | 45 ms
36,408 KB |
testcase_05 | AC | 44 ms
36,648 KB |
testcase_06 | AC | 43 ms
36,896 KB |
testcase_07 | AC | 45 ms
36,688 KB |
testcase_08 | AC | 44 ms
36,856 KB |
testcase_09 | AC | 44 ms
37,036 KB |
testcase_10 | AC | 46 ms
36,892 KB |
testcase_11 | AC | 44 ms
36,684 KB |
testcase_12 | AC | 44 ms
36,540 KB |
testcase_13 | AC | 47 ms
36,780 KB |
testcase_14 | AC | 44 ms
36,740 KB |
testcase_15 | AC | 43 ms
36,764 KB |
testcase_16 | AC | 68 ms
37,956 KB |
testcase_17 | AC | 45 ms
36,840 KB |
testcase_18 | AC | 67 ms
37,876 KB |
testcase_19 | AC | 68 ms
37,944 KB |
testcase_20 | AC | 44 ms
36,888 KB |
testcase_21 | AC | 44 ms
36,896 KB |
testcase_22 | AC | 44 ms
36,652 KB |
testcase_23 | AC | 44 ms
36,516 KB |
testcase_24 | AC | 44 ms
36,540 KB |
testcase_25 | AC | 43 ms
36,672 KB |
testcase_26 | AC | 44 ms
36,852 KB |
testcase_27 | AC | 43 ms
36,744 KB |
testcase_28 | AC | 44 ms
36,684 KB |
testcase_29 | AC | 64 ms
38,120 KB |
testcase_30 | AC | 46 ms
36,592 KB |
testcase_31 | AC | 47 ms
36,868 KB |
testcase_32 | AC | 44 ms
36,560 KB |
testcase_33 | AC | 47 ms
36,496 KB |
testcase_34 | AC | 44 ms
36,856 KB |
testcase_35 | AC | 44 ms
36,796 KB |
testcase_36 | AC | 45 ms
36,648 KB |
testcase_37 | AC | 43 ms
36,588 KB |
testcase_38 | AC | 41 ms
36,832 KB |
testcase_39 | AC | 42 ms
36,760 KB |
testcase_40 | AC | 42 ms
36,636 KB |
testcase_41 | AC | 44 ms
36,852 KB |
ソースコード
import java.io.*; import java.util.*; 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> counts = new HashMap<>(); for (long i = 2; i <= Math.sqrt(m); i++) { while (m % i == 0) { counts.put(i, counts.getOrDefault(i, 0) + 1); m /= i; } } if (m > 1) { counts.put(m, counts.getOrDefault(m, 0) + 1); } long ans = Long.MAX_VALUE; for (long x : counts.keySet()) { int c = counts.get(x); long all = getCount(n, x); long minus1 = getCount(k, x); long minus2 = getCount(n - k, x); ans = Math.min(ans, (all - minus1 - minus2) / c); } System.out.println(ans); } static long getCount(long target, long x) { long count = 0; long y = 1; while (target / y >= x) { y *= x; count += target / y; } return count; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }