#include #define rep(i,a,b) for(int i = a; i < (b); ++i) #define sz(x) (int)(x).size() using namespace std; using ll = long long; using pi = pair; using vi = vector; ll m10[3000]; ll mod = 1000000007; void solve() { int k, p; cin >> k >> p; m10[0] = 1; for(int i = 0; i < 2030; ++i) { m10[i+1] = (10*m10[i]) % p; } ll total = 0; // zero total = 1; // odd { vector ps(p); vector nps(p); ll rk = 0; for(int i = 1; i < 10; ++i) { ps[i % p] += 1; } total += ps[0]; ps[0] += 1; for(int i = 3; i <= k; i += 2) { for(int j = 0; j < p; ++j) { for(int d = 0; d < 10; ++d) { int nj = (1ll*(m10[i-1]*d + 10ll*j + d)) % p; if(d != 0 && nj == 0) { total += ps[j]; total %+ mod; } nps[nj] += ps[j]; nps[nj] %= mod; } } swap(ps, nps); nps.clear(); nps.resize(p, 0); } } // even { vector ps(p); vector nps(p); ll rk = 0; ps[0] = 1; for(int i = 2; i <= k; i += 2) { for(int j = 0; j < p; ++j) { for(int d = 0; d < 10; ++d) { int nj = (1ll*(m10[i-1]*d + 10ll*j + d)) % p; if(d != 0 && nj == 0) { total += ps[j]; total %= mod; } nps[nj] += ps[j]; nps[nj] %= mod; } } swap(ps, nps); nps.clear(); nps.resize(p, 0); } } cout << total << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }