#include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) typedef long long ll; using namespace std; const int mod = 1e9+7; int main() { string s; int m; cin >> s >> m; vector cur(m); vector prv; int ans = 0; for (char c : s) { int d = c - '0'; cur.swap(prv); cur.clear(); cur.resize(m); repeat (i,m) { cur[i] += prv[i]; cur[(i * 10 + d) % m] += prv[i]; if ((i * 10 + d) % m == 0) { ans += prv[i]; } } if (d == 0) { ans += 1; } else { cur[d % m] += 1; if (d % m == 0) { ans += 1; } } repeat (i,m) { cur[i] %= mod; } ans %= mod; } cout << ans << endl; return 0; }