結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-08-01 13:23:03 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 2,526 bytes |
| コンパイル時間 | 3,816 ms |
| コンパイル使用メモリ | 84,536 KB |
| 実行使用メモリ | 50,496 KB |
| 最終ジャッジ日時 | 2024-10-11 05:08:08 |
| 合計ジャッジ時間 | 5,960 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
static int m;
static int k;
static int[] values;
static long[] amounts;
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, 1);
}
values = new int[counts.size()];
amounts = new long[counts.size()];
int idx = 0;
for (int x : counts.keySet()) {
values[idx] = x;
amounts[idx] = counts.get(x);
idx++;
}
System.out.println(dfw(idx - 1, 1));
}
static int dfw(int idx, long v) {
if (idx < 0) {
return 1;
}
long current = 1;
int ans = 0;
for (int i = 0; i <= amounts[idx] * k && v * current <= m; i++) {
ans += dfw(idx - 1, v * current);
current *= values[idx];
}
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();
}
}
tenten