#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vvll = vector<vector<ll>>; using pii = pair<int, int>; const int inf = 1e9; const ll md = 1000000007; int main() { string s; int m; cin>>s>>m; int n=s.size(); vll dp(m,0LL),ndp(m,0LL); dp[0]=1LL;ndp[0]=1LL; rep(i,n){ int a=s[i]-'0'; rep(j,m){ ndp[(j*10+a)%m]+=dp[j]; if (j==0 and a==0) ndp[0]-=1; } rep(j,m) ndp[j]%=md; dp=ndp; //rep(j,m) cout<<dp[j]<<" "; //cout<<endl; } rep(i,n) if(s[i]=='0') dp[0]+=1; cout<<(dp[0]+md-1)%md<<endl; return 0; }