結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-02-16 11:31:11 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 2,531 bytes |
| コンパイル時間 | 2,296 ms |
| コンパイル使用メモリ | 85,824 KB |
| 実行使用メモリ | 37,336 KB |
| 最終ジャッジ日時 | 2024-07-18 13:04:27 |
| 合計ジャッジ時間 | 4,971 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
static int m;
static int[] values;
static int[] counts;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = Math.min(sc.nextInt(), 30);
m = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 2; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
map.put(i, map.getOrDefault(i, 0) + 1);
n /= i;
}
}
if (n > 1) {
map.put(n, map.getOrDefault(n, 0) + 1);
}
int idx = 0;
values = new int[map.size()];
counts = new int[map.size()];
for (int x : map.keySet()) {
values[idx] = x;
counts[idx] = Math.min(30, map.get(x) * k);
idx++;
}
System.out.println(dfw(idx - 1, 1));
}
static int dfw(int idx, long v) {
if (idx < 0) {
return 1;
}
long current = v;
int ans = 0;
for (int i = 0; i <= counts[idx] && current <= m; i++) {
ans += dfw(idx - 1, 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