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 uint[20050]; var next = new uint[20050]; var ans = 0u; var ten = new int[20050]; for (int i = 0; i < m; i++) ten[i] = (i * 10) % m; const int MOD = 1000000007; if (m < 20) { foreach (var x in s) { var v = x - '0'; Buffer.BlockCopy(dp, 0, next, 0, sizeof(uint) * 20050); if (v > 0) next[v % m]++; else ans++; for (int j = 0; j < m; j++) { var to = ten[j] + v; if (to >= m) to %= m; if ((next[to] += dp[j]) >= MOD) next[to] -= MOD; } Swap(ref dp, ref next); } } else { foreach (var x in s) { var v = x - '0'; Buffer.BlockCopy(dp, 0, next, 0, sizeof(uint) * 20050); if (v > 0) next[v % m]++; else ans++; for (int j = 0; j < m; j++) { var to = ten[j] + v; if (to >= m) to -= m; if ((next[to] += dp[j]) >= MOD) next[to] -= 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; } } }