#include using namespace std; #define MAX_M 20001 #define MOD 1000000007 typedef long long ll; int c2i(char c) { return c - '0'; } ll dp[2][MAX_M], res = 0; int main() { string S; int M; cin >> S >> M; memset(dp, 0, sizeof(dp)); dp[0][c2i(S[0]) % M] = 1; res = dp[0][0]; if (c2i(S[0]) == 0) dp[0][c2i(S[0])] = 0; for (int i = 1; i < (int)S.size(); i++) { int si = !(i & 1), ti = !si; int num = c2i(S[i]); int n = num; num %= M; if (num > 0 && n != 0) dp[ti][num]++; for (int j = 0; j < M; j++) { dp[ti][(10*j + num) % M] += dp[si][j]; dp[ti][(10*j + num) % M] %= MOD; dp[ti][j] += dp[si][j]; dp[ti][j] %= MOD; } res += dp[ti][0]; fill(dp[si], dp[si] + M, 0); res %= MOD; } cout << res%MOD << endl; return 0; }