import java.util.*; class Main { public static void main(String[] args) { String s; int m; Scanner sc = new Scanner(System.in); s = sc.next(); m = sc.nextInt(); new Main(s,m); } int m; final int mod = (int)(1e9 + 7); Main(String s, int m) { int len = s.length(); this.m = m; int[][] dp = new int[2][m + 3]; dp[0][0] = 1; int t = 0; for (int i = 1; i <= len; ++i) { t = 1 - t; // alternating, t == i % 2 for (int j = 0; j < m + 3; ++j) { dp[t][j] = dp[1 - t][j]; } for (int j = 0; j < m + 3; ++j) { int pos = next_state(j, s.charAt(i-1)); dp[t][pos] += dp[1 - t][j]; dp[t][pos] %= mod; } } // accepting states are {1, 3} System.out.println((dp[len % 2][1] + dp[len % 2][3]) % mod); } final int next_state(int st, char ch) { if (st == 2) { // fail return 2; } if (st == 1) { // "0" return 2; // This automaton never accepts string of form /0..*/ } if (st == 0) { // init, "" if (ch == '0') { return 1; // "0" } return (ch - '0') % m + 3; } int q = st - 3; return (q * 10 + (ch - '0')) % m + 3; } }