結果

問題 No.847 Divisors of Power
ユーザー htensaihtensai
提出日時 2019-12-09 23:09:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,482 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 75,812 KB
実行使用メモリ 58,068 KB
最終ジャッジ日時 2023-09-05 12:19:59
合計ジャッジ時間 7,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,752 KB
testcase_01 AC 124 ms
55,692 KB
testcase_02 AC 126 ms
55,560 KB
testcase_03 AC 127 ms
55,940 KB
testcase_04 AC 127 ms
55,676 KB
testcase_05 AC 127 ms
55,744 KB
testcase_06 AC 128 ms
56,056 KB
testcase_07 AC 126 ms
56,048 KB
testcase_08 AC 125 ms
56,088 KB
testcase_09 AC 124 ms
55,868 KB
testcase_10 AC 126 ms
55,852 KB
testcase_11 AC 128 ms
55,808 KB
testcase_12 AC 129 ms
58,068 KB
testcase_13 AC 127 ms
56,024 KB
testcase_14 AC 127 ms
56,104 KB
testcase_15 AC 130 ms
55,752 KB
testcase_16 AC 127 ms
55,712 KB
testcase_17 AC 126 ms
55,784 KB
testcase_18 AC 127 ms
55,824 KB
testcase_19 AC 130 ms
55,592 KB
testcase_20 AC 126 ms
56,008 KB
testcase_21 AC 134 ms
56,060 KB
testcase_22 AC 124 ms
55,940 KB
testcase_23 AC 127 ms
55,928 KB
testcase_24 AC 133 ms
55,808 KB
testcase_25 AC 126 ms
55,960 KB
testcase_26 AC 127 ms
55,884 KB
testcase_27 AC 128 ms
56,012 KB
testcase_28 AC 124 ms
55,704 KB
testcase_29 AC 125 ms
56,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
    }
}
0