結果

問題 No.847 Divisors of Power
ユーザー tentententen
提出日時 2022-08-03 15:26:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 75,336 KB
実行使用メモリ 51,144 KB
最終ジャッジ日時 2023-10-11 09:29:39
合計ジャッジ時間 5,336 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,664 KB
testcase_01 AC 40 ms
49,256 KB
testcase_02 AC 42 ms
49,428 KB
testcase_03 AC 41 ms
49,368 KB
testcase_04 AC 40 ms
49,256 KB
testcase_05 AC 41 ms
49,324 KB
testcase_06 AC 41 ms
49,352 KB
testcase_07 AC 41 ms
49,360 KB
testcase_08 AC 42 ms
49,444 KB
testcase_09 AC 41 ms
49,824 KB
testcase_10 AC 41 ms
49,204 KB
testcase_11 AC 41 ms
49,324 KB
testcase_12 AC 42 ms
49,260 KB
testcase_13 AC 43 ms
49,540 KB
testcase_14 AC 41 ms
49,292 KB
testcase_15 AC 54 ms
51,144 KB
testcase_16 AC 41 ms
49,312 KB
testcase_17 AC 40 ms
49,324 KB
testcase_18 AC 43 ms
49,352 KB
testcase_19 AC 43 ms
49,672 KB
testcase_20 AC 42 ms
49,296 KB
testcase_21 AC 52 ms
50,952 KB
testcase_22 AC 42 ms
49,232 KB
testcase_23 AC 41 ms
49,284 KB
testcase_24 AC 54 ms
51,132 KB
testcase_25 AC 43 ms
49,332 KB
testcase_26 AC 43 ms
49,372 KB
testcase_27 AC 44 ms
49,224 KB
testcase_28 AC 44 ms
49,416 KB
testcase_29 AC 42 ms
49,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static int m;
    static long k;
    static int[] values;
    static int[] times;
    static int length;
    static int ans = 0;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        k = sc.nextInt();
        m = sc.nextInt();
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int i = 2; i <= Math.sqrt(n); i++) {
            while (n % i == 0) {
                counts.put(i, counts.getOrDefault(i, 0) + 1);
                n /= i;
            }
        }
        if (n > 1) {
            counts.put(n, counts.getOrDefault(n, 0) + 1);
        }
        int idx = 0;
        length = counts.size();
        values = new int[length];
        times = new int[length];
        for (int x : counts.keySet()) {
            values[idx] = x;
            times[idx] = counts.get(x);
            idx++;
        }
        check(0, 1);
        System.out.println(ans);
    }
    
    static void check(int idx, long v) {
        if (idx >= length) {
            ans++;
            return;
        }
        for (int i = 0; i <= times[idx] * k && v <= m; i++) {
            check(idx + 1, v);
            v *= values[idx];
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0