#include const int mod = 1e9 + 7; char S[10001]; int M; int64_t dp0[20000], dp1[20000]; int main() { scanf("%s %d", S, &M); int n = strlen(S), d = 10 % M; int zero = 0; for (int i = 0; i < n; i++) S[i] -= '0', zero += S[i] == 0; for (int i = 0; i < n; i++) { memcpy(dp1, dp0, sizeof(dp1)); if (S[i] != 0) dp0[S[i] % M]++; for (int j = 0; j < M; j++) dp0[(j * 10 + S[i]) % M] += dp1[j]; if (i % 16 == 0) for (int j = 0; j < M; j++) dp0[i] %= mod; } printf("%lld\n", (dp0[0] + zero) % mod); }