/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pass System Test! */ #include using namespace std; template std::ostream &operator<<(std::ostream &out, const std::vector &v) { if (!v.empty()) { out << '['; std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); out << "\b\b]"; } return out; } template std::ostream &operator<<(std::ostream &out, const std::pair &p) { out << "[" << p.first << ", " << p.second << "]"; return out; } template void chmin(T &t, U f) { if (t > f) t = f; } template void chmax(T &t, U f) { if (t < f) t = f; } template void uniq(vector &v) { v.erase(unique(v.begin(), v.end()), v.end()); } const int MOD = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); string inS; cin >> inS; int N = inS.size(); vector S(N); for (int i = 0; i < N; ++i) S[i] = inS[i] - '0'; int M; cin >> M; vector> remainer(M, vector(10, 0)); for (int i = 0; i < M; ++i) for (int j = 0; j < 10; ++j) remainer[i][j] = (i * 10 + j) % M; vector dp(M, 0); dp[0] = 1; int zeros = 0; for (int i = 0; i < N; ++i) { vector next(M, 0); for (int m = 0; m < M; ++m) { next[m] += dp[m]; next[m] %= MOD; int r = remainer[m][S[i]]; next[r] += dp[m]; if (m == 0 && S[i] == 0) { zeros++; next[r] = (next[r] - 1 + MOD) % MOD; } else { next[r] %= MOD; } } dp.swap(next); } cout << ((dp[0] + zeros - 1 + MOD) % MOD) << endl; }