#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  string S;
  cin >> S;
  int L = S.size();
  int M;
  cin >> M;

  ll dp[M];
  memset(dp, 0, sizeof(dp));
  int zero_cnt = 0;

  for (int i = 0; i < L; ++i) {
    int d = S[i] - '0';
    ll temp[M];
    memcpy(temp, dp, sizeof(dp));

    if (d != 0) {
      temp[d % M] += 1;
      temp[d % M] %= MOD;
    } else {
      ++zero_cnt;
    }

    for (int m = 0; m < M; ++m) {
      int nm = (10 * m + d) % M;
      temp[nm] += dp[m];
      temp[nm] %= MOD;
    }

    memcpy(dp, temp, sizeof(temp));
  }

  cout << (dp[0] + zero_cnt) % MOD << endl;

  return 0;
}