結果

問題 No.847 Divisors of Power
ユーザー tentententen
提出日時 2023-08-01 13:23:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,526 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 92,136 KB
実行使用メモリ 38,260 KB
最終ジャッジ日時 2024-04-19 12:47:32
合計ジャッジ時間 4,702 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
37,232 KB
testcase_01 AC 49 ms
37,028 KB
testcase_02 AC 47 ms
37,332 KB
testcase_03 AC 46 ms
37,280 KB
testcase_04 AC 48 ms
37,308 KB
testcase_05 AC 49 ms
37,156 KB
testcase_06 AC 46 ms
37,168 KB
testcase_07 AC 46 ms
36,928 KB
testcase_08 AC 47 ms
37,144 KB
testcase_09 AC 47 ms
37,116 KB
testcase_10 AC 46 ms
37,236 KB
testcase_11 AC 48 ms
37,112 KB
testcase_12 AC 50 ms
37,236 KB
testcase_13 AC 47 ms
37,148 KB
testcase_14 AC 47 ms
37,008 KB
testcase_15 AC 58 ms
37,476 KB
testcase_16 AC 48 ms
36,772 KB
testcase_17 AC 47 ms
37,080 KB
testcase_18 AC 47 ms
37,276 KB
testcase_19 AC 49 ms
37,080 KB
testcase_20 AC 50 ms
37,116 KB
testcase_21 AC 52 ms
37,256 KB
testcase_22 AC 47 ms
37,264 KB
testcase_23 AC 45 ms
37,332 KB
testcase_24 AC 58 ms
38,260 KB
testcase_25 AC 48 ms
37,228 KB
testcase_26 AC 48 ms
37,144 KB
testcase_27 AC 49 ms
37,412 KB
testcase_28 AC 46 ms
36,916 KB
testcase_29 AC 47 ms
36,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int m;
    static int k;
    static int[] values;
    static long[] amounts;
    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, 1);
        }
        values = new int[counts.size()];
        amounts = new long[counts.size()];
        int idx = 0;
        for (int x : counts.keySet()) {
            values[idx] = x;
            amounts[idx] = counts.get(x);
            idx++;
        }
        System.out.println(dfw(idx - 1, 1));
    }
    
    static int dfw(int idx, long v) {
        if (idx < 0) {
            return 1;
        }
        long current = 1;
        int ans = 0;
        for (int i = 0; i <= amounts[idx] * k && v * current <= m; i++) {
            ans += dfw(idx - 1, v * current);
            current *= values[idx];
        }
        return ans;
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0