結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-10-06 11:23:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 1,885 bytes |
| コンパイル時間 | 2,926 ms |
| コンパイル使用メモリ | 80,952 KB |
| 実行使用メモリ | 39,588 KB |
| 最終ジャッジ日時 | 2025-01-02 21:07:39 |
| 合計ジャッジ時間 | 5,362 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static HashMap<Integer, Integer> counts = new HashMap<>();
static long k;
static int m;
static int[] values;
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();
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;
values = new int[counts.size()];
for (int x : counts.keySet()) {
values[idx++] = x;
}
calc(idx - 1, 1);
System.out.println(ans);
}
static void calc(int idx, long v) {
if (idx < 0) {
ans++;
return;
}
for (int i = 0; i <= k * counts.get(values[idx]) && v <= m; i++) {
calc(idx - 1, v);
v *= values[idx];
}
}
}
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 String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten