import java.io.*; import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] values = sc.next().toCharArray(); int k = sc.nextInt(); int length = values.length; int[] prev = new int[k]; int[] next = new int[k]; int ans = 0; for (int i = 0; i < length; i++) { int x = values[i] - '0'; for (int j = 0; j < k && i > 0; j++) { if (prev[j] > 0) { next[(j * 10 + x) % k] += prev[j]; next[(j * 10 + x) % k] %= MOD; next[j] += prev[j]; next[j] %= MOD; } } if (x == 0) { ans++; ans %= MOD; } else { next[x % k]++; } int[] tmp = prev; prev = next; next = tmp; Arrays.fill(next, 0); } System.out.println((ans + prev[0]) % MOD); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }