#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using vll = vector; using vi = vector; using vvi = vector>; using vvll = vector>; using pii = pair; 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(i,n) if(s[i]=='0') dp[0]+=1; cout<