結果

問題 No.847 Divisors of Power
ユーザー k_6101k_6101
提出日時 2019-12-07 21:35:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 3,043 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 79,732 KB
実行使用メモリ 57,600 KB
最終ジャッジ日時 2023-08-27 03:13:04
合計ジャッジ時間 7,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,900 KB
testcase_01 AC 121 ms
55,556 KB
testcase_02 AC 119 ms
55,316 KB
testcase_03 AC 121 ms
55,796 KB
testcase_04 AC 123 ms
56,004 KB
testcase_05 AC 123 ms
55,828 KB
testcase_06 AC 124 ms
57,600 KB
testcase_07 AC 125 ms
55,588 KB
testcase_08 AC 127 ms
55,656 KB
testcase_09 AC 128 ms
55,576 KB
testcase_10 AC 125 ms
55,652 KB
testcase_11 AC 125 ms
55,720 KB
testcase_12 AC 126 ms
55,716 KB
testcase_13 AC 126 ms
55,560 KB
testcase_14 AC 125 ms
55,600 KB
testcase_15 AC 133 ms
55,776 KB
testcase_16 AC 124 ms
55,552 KB
testcase_17 AC 126 ms
55,620 KB
testcase_18 AC 126 ms
55,688 KB
testcase_19 AC 121 ms
55,696 KB
testcase_20 AC 123 ms
55,656 KB
testcase_21 AC 127 ms
55,364 KB
testcase_22 AC 122 ms
55,676 KB
testcase_23 AC 123 ms
55,544 KB
testcase_24 AC 129 ms
55,396 KB
testcase_25 AC 123 ms
55,840 KB
testcase_26 AC 120 ms
55,792 KB
testcase_27 AC 123 ms
55,836 KB
testcase_28 AC 122 ms
55,716 KB
testcase_29 AC 123 ms
55,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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, long total) {
//    	out.println("now = " + now + "  total = " + total);
    	if(now >= X.length)		return 1;	// 約数すが、ひとつ見つかった
    	int ans = 0;
    	long 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));
    }
    // ==================================================================
}
0