#include #define mp make_pair #define mt make_tuple #define pb push_back #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; const int INF=1<<29; const double EPS=1e-9; const int MOD = 1000000007; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; const int MAX_M = 20010; string S; int M; int dp[2][2][MAX_M]; int main(){ cin >> S; cin >> M; memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; for (int i = 0; i < S.size(); i++){ for (int l = 0; l < 2; l++){ for (int j = 0; j < M; j++){ if (dp[i % 2][l][j] == 0)continue; dp[(i + 1) % 2][l][j] += dp[i % 2][l][j]; dp[(i + 1) % 2][l][j] %= MOD; if (l == 0 and (S[i] - '0') == 0){ continue; } int k = (j * 10 + (S[i] - '0')) % M; dp[(i + 1) % 2][1][k % M] += dp[i % 2][l][j]; dp[(i + 1) % 2][1][k % M] %= MOD; } } int now = i % 2; for (int k = 0; k < 2; k++){ for (int j = 0; j < M; j++){ dp[now][k][j] = 0; } } } int result = 0; result = dp[S.size() % 2][1][0]; for (const auto &val : S){ if (val == '0'){ result++; result %= MOD; } } cout << result << endl; }