#include using namespace std; long long dp[2][20001]; int nex[20001][10]; int M = 1000000007; int main(){ string s; cin >> s; int n = s.length(), m, k; cin >> m; int zero = -1; dp[0][0] = 1; for (int i = 0; i < m; ++i) { for (int j = 0; j < 10; ++j) { nex[i][j] = (i * 10 + j) % m; } } for (int i = 0, ii = 0; i < n; ++i, ii ^= 1) { int t = s[i] - '0'; for (int j = 0; j < m; j++) { dp[ii ^ 1][j] += dp[ii][j]; dp[ii ^ 1][nex[j][t]] += dp[ii][j]; } if (!t) { dp[ii ^ 1][0] += M - 1; ++zero; } for (int j = 0; j < m; ++j) { dp[ii ^ 1][j] %= M; dp[ii][j] = 0; } } cout << (dp[n & 1][0] + zero) % M << "\n"; return 0; }