結果

問題 No.473 和と積の和
ユーザー 37zigen37zigen
提出日時 2016-12-24 19:13:24
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,495 ms / 3,000 ms
コード長 1,371 bytes
コンパイル時間 6,247 ms
コンパイル使用メモリ 79,972 KB
実行使用メモリ 364,416 KB
最終ジャッジ日時 2023-08-22 09:22:46
合計ジャッジ時間 19,643 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,016 KB
testcase_01 AC 121 ms
55,748 KB
testcase_02 AC 121 ms
56,100 KB
testcase_03 AC 621 ms
133,032 KB
testcase_04 AC 122 ms
55,820 KB
testcase_05 AC 123 ms
55,948 KB
testcase_06 AC 123 ms
56,100 KB
testcase_07 AC 121 ms
56,176 KB
testcase_08 AC 120 ms
56,440 KB
testcase_09 AC 121 ms
56,276 KB
testcase_10 AC 122 ms
55,948 KB
testcase_11 AC 123 ms
55,440 KB
testcase_12 AC 121 ms
55,804 KB
testcase_13 AC 123 ms
55,756 KB
testcase_14 AC 123 ms
55,780 KB
testcase_15 AC 124 ms
55,912 KB
testcase_16 AC 127 ms
56,128 KB
testcase_17 AC 126 ms
55,968 KB
testcase_18 AC 123 ms
56,228 KB
testcase_19 AC 121 ms
56,112 KB
testcase_20 AC 129 ms
55,804 KB
testcase_21 AC 122 ms
55,764 KB
testcase_22 AC 124 ms
55,508 KB
testcase_23 AC 154 ms
58,428 KB
testcase_24 AC 160 ms
58,656 KB
testcase_25 AC 1,495 ms
248,644 KB
testcase_26 AC 482 ms
116,228 KB
testcase_27 AC 636 ms
133,144 KB
testcase_28 AC 135 ms
55,996 KB
testcase_29 AC 149 ms
56,804 KB
testcase_30 AC 149 ms
56,952 KB
testcase_31 AC 148 ms
57,160 KB
testcase_32 AC 127 ms
56,088 KB
testcase_33 AC 127 ms
55,768 KB
testcase_34 AC 929 ms
194,608 KB
testcase_35 AC 856 ms
150,396 KB
testcase_36 AC 142 ms
56,620 KB
testcase_37 AC 125 ms
56,028 KB
testcase_38 AC 822 ms
142,368 KB
testcase_39 AC 479 ms
95,040 KB
testcase_40 AC 509 ms
116,028 KB
testcase_41 AC 852 ms
364,416 KB
testcase_42 AC 489 ms
133,348 KB
testcase_43 AC 622 ms
139,032 KB
testcase_44 AC 775 ms
193,408 KB
testcase_45 AC 124 ms
55,728 KB
testcase_46 AC 123 ms
56,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q473 {
	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int x = sc.nextInt();
		++x;
		int[] div = new int[10000];
		int pos = 0;
		for (int i = 1; i * i <= x; ++i) {
			if (x % i == 0) {
				div[pos++] = i;
				if (i * i != x) {
					div[pos++] = x / i;
				}
			}
		}
		div = Arrays.copyOf(div, pos);
		Arrays.sort(div);
		map = new long[pos][pos + 1][n + 1];
		for (int i = 0; i < map.length; ++i) {
			for (int j = 0; j < map[i].length; ++j) {
				for (int k = 0; k < map[i][j].length; ++k) {
					map[i][j][k] = -1;
				}
			}
		}
		System.out.println(dfs(x, div, 1, 0));
	}

	static long[][][] map;

	static long dfs(int cur, int[] div, int pos, int count) {
		if (map[Arrays.binarySearch(div, cur)][pos][count] != -1) {
			return map[Arrays.binarySearch(div, cur)][pos][count];
		}
		if (count == n) {
			if (cur == 1)
				return 1;
			else
				return 0;
		}
		if (div.length == pos || count >= n)
			return 0;
		else {
			long ret = 0;
			if (cur % div[pos] == 0) {
				ret += dfs(cur / div[pos], div, pos, count + 1);
			}
			ret += dfs(cur, div, pos + 1, count);
			map[Arrays.binarySearch(div, cur)][pos][count] = ret;
			return ret;
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0