import std; import core.checkedint; void main() { long N, M; readf("%d %d\n", N, M); long MOD = 10 ^^ 9 + 7; long S = M.to!real.sqrt.floor.to!long; long[] divisors; bool[long] isDivisor; foreach (i; 1 .. S+1) { if (M % i != 0) continue; divisors ~= i; isDivisor[i] = true; if (i * i != M) { divisors ~= M / i; isDivisor[M/i] = true; } } divisors.sort; auto len = divisors.length; auto mat = new long[][](len, len); foreach (i, d1; divisors) { foreach (j, d2; divisors) { bool isOver; long num = muls(d1, d2, isOver); if (isOver || num > M) break; if (num in isDivisor) { mat[i][j] = 1; } } } auto A = matPowMod(mat, N-1, MOD); long res; foreach (a; A) { foreach (x; a) res = (res + x) % MOD; } res.writeln; } long[][] matMulMod(long[][] a, long[][] b, long m) { long l = a[0].length.to!long; assert(l == b.length); auto res = new long[][](a.length, b[0].length); foreach (i, r; res) { foreach (k; 0 .. l) { foreach (j, ref e; r) { e = (e + a[i][k] * b[k][j]) % m; } } } return res; } long[][] matPowMod(long[][] mat, long p, long m) { long l = mat[0].length.to!long; assert(l == mat.length); auto res = new long[][](l, l); foreach (i; 0 .. l) { res[i][i] = 1; } while (p > 0) { if (p & 1) { res = matMulMod(res, mat, m); } mat = matMulMod(mat, mat, m); p >>= 1; } return res; }