#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); const long long MOD = 1e9 + 7; long long dp[2][20000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int m; cin >> m; long long ret = 0; REP (i, s.length()) { int cur = i & 1; int nxt = (i+1) & 1; memset(dp[nxt], 0, sizeof(dp[nxt])); int x = s[i] - '0'; REP (j, m) { dp[nxt][(x + j) % m] += dp[cur][j]; dp[nxt][(x + j) % m] %= MOD; } REP (j, m) { dp[nxt][j] += dp[cur][j]; dp[nxt][j] %= MOD; } if (x == 0) { ++ret; } else { dp[nxt][x % m]++; } } ret += dp[s.length() & 1][0]; ret %= MOD; cout << ret << endl; return 0; }