#include using namespace std; long long dp[2][20001]; 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, ii = 0; i < n; ++i, ii ^= 1) { for (int j = 0; j < m; j++) { dp[ii ^ 1][j] = (dp[ii ^ 1][j] + dp[ii][j]) % M; k = (j * 10 + s[i] - '0') % m; dp[ii ^ 1][k] = (dp[ii ^ 1][k] + dp[ii][j]) % M; dp[ii][j] = 0; } if (s[i] == '0') { if (dp[ii ^ 1][0]) --dp[ii ^ 1][0]; else dp[ii ^ 1][0] = M - 1; ++zero; } } cout << (dp[n & 1][0] + zero) % M << "\n"; return 0; }