import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp.map!(a => (a - '0').to!int).array, n = s.length; auto m = readln.chomp.to!int; auto dp = new int[][][](n+1, 2, m); dp[0][0][0] = 1; foreach (p; 0..n) foreach (q; 0..2) foreach (r; 0..m) if (s[p] > 0) { dp[p+1][1][(r * 10 + s[p]) % m] += dp[p][q][r]; dp[p+1][q][r] += dp[p][q][r]; } else { if (q == 1) dp[p+1][1][r * 10 % m] += dp[p][q][r]; dp[p+1][q][r] += dp[p][q][r]; } writeln(dp[n][1][0] + s.count(0)); }