#include using namespace std; static const long long MOD = 1000000007; int main() { string S; int M; cin >> S >> M; // dp[state][mod] vector> dp(3, vector(M, 0)); dp[0][0] = 1; // 何も選んでいない for (char c : S) { int x = c - '0'; auto ndp = dp; // 「使わない」遷移 for (int st = 0; st < 3; st++) { for (int m = 0; m < M; m++) { long long v = dp[st][m]; if (v == 0) continue; if (st == 0) { // 初めて選ぶ int nst = 1; int nm = x % M; ndp[nst][nm] = (ndp[nst][nm] + v) % MOD; } else { // 2文字以上 int nst = 2; int nm = (m * 10 + x) % M; ndp[nst][nm] = (ndp[nst][nm] + v) % MOD; } } } dp.swap(ndp); } long long ans = 0; // 長さ1 ans = (ans + dp[1][0]) % MOD; // 長さ2以上 ans = (ans + dp[2][0]) % MOD; cout << ans << '\n'; return 0; }