#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int; using vi = vector; using vb = vector; using vd = vector; using vl = vector; using vvi = vector; using vvb = vector; using vvd = vector; using vvl = vector; #define REP(i,n) for(ll i=0; i<(n); ++i) #define FOR(i,b,n) for(ll i=(b); i<(n); ++i) #define ALL(v) (v).begin(), (v).end() #define TEN(x) ((ll)1e##x) template inline string join(const vector& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); } vb eratosthenes(ll n) { vb t(n+1, true); t[0] = t[1] = false; for(ll i = 2; i <= n; ++i) if (t[i]){ for(ll j = 2*i; j <= n; j += i) t[j] = false; } return t; } vl compress(const vb & t) { vl v; v.reserve((ll)(1.2 * t.size() / log(t.size()))); REP(i, t.size()) if (t[i]) v.push_back(i); return v; } ll min_prime(ll n) { ll x = sqrt(n); FOR(i, 2, x+1) if (n%i == 0) return i; return 1; } int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); string s; ll m; cin >> s >> m; ll mod = TEN(9) + 7; vector dp(s.size()+1, vvl(m, vl(2, 0))); // dp[s.size()][m][ζœ€εΎŒγŒ0か] dp[0][0][0] = 1; REP(i, s.size()) REP(j, m) REP(k, 2) { (dp[i+1][(j + s[s.size() - 1 - i] - '0')%m][s[s.size() - 1 - i]=='0'] += dp[i][j][k]) %= mod; (dp[i+1][j][k] += dp[i][j][k]) %= mod; } cout << dp[s.size()][0][0] << endl; return 0; }