結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-09 23:09:03 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 141 ms / 2,000 ms |
| コード長 | 1,482 bytes |
| コンパイル時間 | 3,125 ms |
| コンパイル使用メモリ | 79,224 KB |
| 実行使用メモリ | 41,568 KB |
| 最終ジャッジ日時 | 2024-06-23 07:58:34 |
| 合計ジャッジ時間 | 7,049 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
import java.util.*;
public class Main {
static int m;
static int[] keys;
static long[] values;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long k = sc.nextInt();
m = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 2; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
if (map.containsKey(i)) {
map.put(i, map.get(i) + 1);
} else {
map.put(i, 1);
}
n /= i;
}
}
if (n != 1) {
if (map.containsKey(n)) {
map.put(n, map.get(n) + 1);
} else {
map.put(n, 1);
}
}
keys = new int[map.size()];
values = new long[map.size()];
int idx = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
keys[idx] = entry.getKey();
values[idx] = entry.getValue() * k;
idx++;
}
System.out.println(search(0, 1));
}
static long search(int idx, long v) {
if (idx >= keys.length) {
return 1;
}
long ans = 0;
long count = 0;
while (v <= m && count <= values[idx]) {
ans += search(idx + 1, v);
v *= keys[idx];
count++;
}
return ans;
}
}
htensai