#include "bits/stdc++.h" using namespace std; #define rt return #define FOR(i,j,k) for(int i=j; i<(int)k;++i) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; template class ModInt{ public: ModInt():value(0){} ModInt(long long val):value(val<0?MOD+val%MOD:val%MOD){ } ModInt& operator+=(ModInt that){ value = value+that.value; if(value>=MOD)value-=MOD; return *this; } ModInt& operator-=(ModInt that){ value -= that.value; if(value<0)value+=MOD; return *this; } ModInt& operator*=(ModInt that){ value = value * that.value % MOD; return *this; } ModInt &operator/=(ModInt that){ return *this *= that.inverse(); } ModInt operator+(ModInt that) const{ return ModInt(*this)+=that; } ModInt operator-(ModInt that) const{ return ModInt(*this)-=that; } ModInt operator*(ModInt that) const{ return ModInt(*this)*=that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt operator^(long long k) const{ ModInt n = *this, res = 1; while(k){ if(k & 1)res *= n; n *= n; k >>= 1; } return res; } ModInt inverse() const { long long a = value, b = MOD, u = 1, v = 0; while(b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } long long toll() const{ return value; } int toi() const{ return (int)value; } private: long long value; }; typedef ModInt<1000000007ll> mint; mint dp[2][20000]; string S; int M; int main(){ ios::sync_with_stdio(0); cin.tie(0); while(cin >> S >> M){ mint ans = count(all(S), '0'); each(c, S)c -= '0'; rep(i, M)dp[0][i] = 0; // reverse(all(S)); rep(i, sz(S)){ int cur = i & 1, nex = 1 - cur; rep(j, M)dp[nex][j] = 0; rep(j, M){ dp[nex][j] += dp[cur][j]; int nj = (j * 10 + S[i]) % M; dp[nex][nj] += dp[cur][j]; } if(S[i]!=0)dp[nex][S[i] % M] += 1; } ans += dp[sz(S) & 1][0]; cout << ans.toi() << endl; } }