/+ dub.sdl: name "A" dependency "dcomp" version=">=0.0.2" +/ import std.stdio, std.conv, std.algorithm; // import dcomp.scanner; Scanner sc; static this() {sc = new Scanner();} int[] divlist; int[][] nx; int main() { int N, X; sc.read(N, X); X++; for (int i = 1; i*i <= X; i++) { if (X % i == 0) { divlist ~= i; if (i*i != X) divlist ~= X/i; } } sort(divlist); int M = divlist.length.to!int; int[int] p2id; foreach (i, d; divlist) { p2id[d] = i.to!int; } nx = new int[][](M, M); foreach (i; 0..M) { foreach(j; 0..M) { int A = divlist[i]; int B = divlist[j]; if (A % B) { nx[i][j] = -1; } else { nx[i][j] = p2id[A/B]; } } } auto dp1 = new int[][](M, M); dp1[0][] = 1; foreach (fe; 0..N) { auto dp2 = new int[][](M, M); foreach (i; 0..M) { foreach_reverse (j; 0..M) { if (j < M-1) dp2[i][j] += dp2[i][j+1]; if (nx[i][j] != -1) dp2[i][j] += dp1[nx[i][j]][j]; } } dp1 = dp2; } writeln(dp1[M-1][1]); return 0; } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File, readln, stdin; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeString, isDynamicArray; import std.algorithm : map; File f; this(File f = stdin) { this.f = f; } string[] buf; bool succ() { while (!buf.length) { if (f.eof) return false; buf = readln.split; } return true; } int read(Args...)(auto ref Args args) { foreach (i, ref v; args) { if (!succ()) return i; alias VT = typeof(v); static if (!isSomeString!VT && isDynamicArray!VT) { v = buf.map!(to!(ElementType!VT)).array; buf.length = 0; } else { v = buf.front.to!VT; buf.popFront(); } } return args.length; } }