結果
問題 |
No.847 Divisors of Power
|
ユーザー |
![]() |
提出日時 | 2022-08-03 15:26:07 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 1,986 bytes |
コンパイル時間 | 2,303 ms |
コンパイル使用メモリ | 78,540 KB |
実行使用メモリ | 50,868 KB |
最終ジャッジ日時 | 2024-09-13 08:40:42 |
合計ジャッジ時間 | 4,987 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import java.io.*; import java.util.*; public class Main { static int m; static long k; static int[] values; static int[] times; static int length; static int ans = 0; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); k = sc.nextInt(); m = sc.nextInt(); HashMap<Integer, Integer> counts = new HashMap<>(); for (int i = 2; i <= Math.sqrt(n); i++) { while (n % i == 0) { counts.put(i, counts.getOrDefault(i, 0) + 1); n /= i; } } if (n > 1) { counts.put(n, counts.getOrDefault(n, 0) + 1); } int idx = 0; length = counts.size(); values = new int[length]; times = new int[length]; for (int x : counts.keySet()) { values[idx] = x; times[idx] = counts.get(x); idx++; } check(0, 1); System.out.println(ans); } static void check(int idx, long v) { if (idx >= length) { ans++; return; } for (int i = 0; i <= times[idx] * k && v <= m; i++) { check(idx + 1, v); v *= values[idx]; } } } 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 { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }