結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
k_6101
|
| 提出日時 | 2019-12-07 21:32:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,032 bytes |
| コンパイル時間 | 4,403 ms |
| コンパイル使用メモリ | 82,336 KB |
| 実行使用メモリ | 41,604 KB |
| 最終ジャッジ日時 | 2024-12-26 09:57:25 |
| 合計ジャッジ時間 | 10,879 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 WA * 18 |
ソースコード
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
import static java.util.Comparator.*;
public class Main {
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
Solver solver = new Solver(System.in, out);
solver.solve();
out.close();
}
}
class Solver {
Scanner sc;
PrintWriter out;
public Solver(InputStream in, PrintWriter out) {
sc = new Scanner(in);
this.out = out;
}
// ==================================================================
// 単純な素因数分解
Map<Long, Long> dec(long n){
// 割った数を保存するマップ 3で2回割れたら、ans.get(3) == 2 となる
// Map<Long, Long> ans = new HashMap<Long, Long>();
Map<Long, Long> ans = new TreeMap<Long, Long>(Collections.reverseOrder());
long num = n;
Long wk = 0L;
// 2 ~ ルートn の間、繰り返す
for(long i = 2; i * i <= n && num != 1; ++i){
// i で割り切れる間、割る
while(num % i == 0){
num /= i;
wk = ans.get(i);
if(wk == null) {
ans.put(i, 1L);
} else {
ans.replace(i, (wk+1L));
}
}
}
if(num != 1) {
wk = ans.get(num);// 最後に残った数も含める
if(wk == null) {
ans.put(num, 1L);
} else {
ans.replace(num, (wk+1L));
}
}
return ans;
}
long N, K, M;
int[] X;
long[] Y;
int dfs(int now, int total) {
// out.println("now = " + now + " total = " + total);
if(now >= X.length) return 1; // 約数すが、ひとつ見つかった
int ans = 0, wk = total;
for (int i = 0; i <= Y[now]; i++) {
if(i > 0) wk *= X[now];
if(wk > M) break;
ans += dfs(now + 1, wk);
}
// out.println("now = " + now + " total = " + total + " --> ans = " + ans);
return ans;
}
public void solve() {
N = Integer.parseInt(sc.next());
K = Integer.parseInt(sc.next());
M = Integer.parseInt(sc.next());
Map<Long, Long> map = dec(N);
X = new int[map.keySet().size()];
Y = new long[map.keySet().size()];
int cnt = 0;
for(long key : map.keySet()) {
X[cnt] = (int)key;
Y[cnt] = map.get(key) * K;
// out.println("X = " + X[cnt] + " Y = " + Y[cnt]);
cnt++;
}
out.println(dfs(0, 1));
}
// ==================================================================
}
k_6101