#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() #define mod 1000000007 #define inf 2000000007 #define mp make_pair #define pb push_back typedef long long ll; using namespace std; template inline void output(T a, int p) { if(p) cout << fixed << setprecision(p) << a << "\n"; else cout << a << "\n"; } // end of template int main() { cin.tie(0); ios::sync_with_stdio(0); // source code string S; int M; cin >> S >> M; vector zero((int)S.size(), 0); repd(i, 1, S.size()){ if(S[i - 1] == '0'){ zero[i] = zero[i - 1] + 1; } else { zero[i] = zero[i - 1]; } } vector dp(M, 0), tmp(M, 0); rep(i, S.size()){ tmp.assign(M, 0); tmp[(S[i] - '0') % M] = 1; rep(j, M){ if(j == 0){ (tmp[(j + (S[i] - '0')) % M] += (dp[j] - zero[i] + mod)) %= mod; } else { (tmp[(j + (S[i] - '0')) % M] += dp[j]) %= mod; } } rep(j, M){ (dp[j] += tmp[j]) %= mod; } } output(dp[0], 0); return 0; }