// TLE するだろうなぁ... #include using namespace std; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FORR(x,arr) for(auto&& x:arr) #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--) #define REP(i,n) for (int i = 0; i < (n); i++) #define RREP(i,n) for (int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) typedef long long ll; // ------------------------------------- const long long mod = 1000000007; string S; int M; int N; int dp[10000][20000]; int calc(int p) { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; REP(i, N-p) REP(j, M) { int d = S[p+i] - '0'; (dp[i+1][(j * 10 + d) % M] += dp[i][j]) %= mod; (dp[i+1][j] += dp[i][j]) %= mod; } return dp[N-p][0]; } void Main() { cin >> S >> M; N = SZ(S); int ans = calc(0); REP(i, N) { if (S[i] == '0') { ans = (ans - calc(i+1) + mod) % mod; } } _P("%d\n", ans); } int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }