結果

問題 No.473 和と積の和
ユーザー 37zigen
提出日時 2016-12-24 02:28:23
言語 Java
(openjdk 23)
結果
MLE  
実行時間 -
コード長 838 bytes
コンパイル時間 4,653 ms
コンパイル使用メモリ 79,564 KB
実行使用メモリ 801,832 KB
最終ジャッジ日時 2024-12-16 03:26:07
合計ジャッジ時間 101,638 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 2
other AC * 16 TLE * 13 MLE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q473 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		// a+b+ab=N
		// (a+1)(b+1)=N+1
		ArrayDeque<List<Long>> que = new ArrayDeque<>();
		que.add(Arrays.asList(x));
		HashSet<List<Long>> ans = new HashSet<>();
		while (!que.isEmpty()) {
			List<Long> lis = que.poll();
			if (lis.size() == n) {
				lis.sort(null);
				ans.add(lis);
			} else {
				for (long d : lis) {
					for (int i = 2; i * i <= (d + 1); ++i) {
						if ((d + 1) % i == 0) {
							List<Long> tmp = new ArrayList();
							tmp.addAll(lis);
							tmp.remove(d);
							tmp.add((long) (i - 1));
							tmp.add((long) ((d + 1) / i - 1));
							que.add(tmp);
						}
					}
				}
			}
		}
		System.out.println(ans.size());
	}
}
0