結果

問題 No.847 Divisors of Power
ユーザー ks2mks2m
提出日時 2019-07-05 22:05:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,450 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 81,676 KB
実行使用メモリ 52,416 KB
最終ジャッジ日時 2024-04-16 07:22:26
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
40,192 KB
testcase_01 AC 137 ms
41,188 KB
testcase_02 AC 120 ms
40,148 KB
testcase_03 AC 132 ms
41,180 KB
testcase_04 AC 122 ms
40,144 KB
testcase_05 AC 130 ms
40,868 KB
testcase_06 AC 119 ms
40,176 KB
testcase_07 AC 120 ms
40,204 KB
testcase_08 AC 135 ms
41,144 KB
testcase_09 AC 134 ms
41,196 KB
testcase_10 AC 135 ms
41,204 KB
testcase_11 AC 121 ms
40,160 KB
testcase_12 AC 134 ms
41,344 KB
testcase_13 AC 139 ms
41,412 KB
testcase_14 AC 133 ms
41,208 KB
testcase_15 AC 293 ms
52,304 KB
testcase_16 AC 133 ms
41,372 KB
testcase_17 AC 136 ms
41,468 KB
testcase_18 AC 134 ms
41,216 KB
testcase_19 AC 118 ms
40,320 KB
testcase_20 AC 132 ms
41,084 KB
testcase_21 AC 188 ms
43,776 KB
testcase_22 AC 133 ms
41,452 KB
testcase_23 AC 132 ms
41,344 KB
testcase_24 AC 323 ms
52,416 KB
testcase_25 AC 134 ms
41,088 KB
testcase_26 AC 132 ms
41,276 KB
testcase_27 AC 120 ms
40,168 KB
testcase_28 AC 136 ms
41,332 KB
testcase_29 AC 130 ms
41,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		if (n == 1) {
			System.out.println(1);
			return;
		}

		Map<Integer, Long> soinsu = bunkai(n);
		Integer[] keys = soinsu.keySet().toArray(new Integer[0]);
		Long[] vals = soinsu.values().toArray(new Long[0]);
		for (int i = 0; i < vals.length; i++) {
			vals[i] *= k;
		}

		Set<Long> set = new HashSet<Long>();
		set.add(1L);
		for (int i = 0; i < keys.length; i++) {
			Long[] o = set.toArray(new Long[0]);
			for (int j = 0; j < o.length; j++) {
				long x = m / o[j];
				long y = 1;
				for (int j2 = 0; j2 < vals[i]; j2++) {
					y *= keys[i];
					if (y <= x) {
						set.add(y * o[j]);
					} else {
						break;
					}
				}
			}
		}
		System.out.println(set.size());
	}

	static Map<Integer, Long> bunkai(int n) {
		Map<Integer, Long> soinsu = new HashMap<Integer, Long>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1L);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0