using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using System.Numerics; using Number = System.Int64; using Point = System.Numerics.Complex; namespace Program { public class Solver { static void Main() { var s = Console.ReadLine(); var m = int.Parse(Console.ReadLine()); var n = s.Length; var dp = new int[32768]; var next = new int[32768]; int ans = 0; var to = new int[10][]; for (int i = 0; i < 10; i++) { to[i] = new int[32768]; for (int j = 0; j < m; j++) to[i][j] = (j * 10 + i) % m; } const int MOD = 1000000007; foreach (var x in s) { var v = x - '0'; Buffer.BlockCopy(dp, 0, next, 0, sizeof(int) * 32768); if (v > 0) next[v % m]++; else ans++; for (int j = 0; j < m; j += 8) { if ((next[to[v][j]] += dp[j]) >= MOD) next[to[v][j]] -= MOD; if ((next[to[v][j + 1]] += dp[j + 1]) >= MOD) next[to[v][j + 1]] -= MOD; if ((next[to[v][j + 2]] += dp[j + 2]) >= MOD) next[to[v][j + 2]] -= MOD; if ((next[to[v][j + 3]] += dp[j + 3]) >= MOD) next[to[v][j + 3]] -= MOD; if ((next[to[v][j + 4]] += dp[j + 4]) >= MOD) next[to[v][j + 4]] -= MOD; if ((next[to[v][j + 5]] += dp[j + 5]) >= MOD) next[to[v][j + 5]] -= MOD; if ((next[to[v][j + 6]] += dp[j + 6]) >= MOD) next[to[v][j + 6]] -= MOD; if ((next[to[v][j + 7]] += dp[j + 7]) >= MOD) next[to[v][j + 7]] -= MOD; } Swap(ref dp, ref next); } Console.WriteLine((dp[0] + ans) % MOD); } static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } }