import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int length = arr.length; int m = sc.nextInt(); int[] prev = new int[m]; int[] next = new int[m]; long ans = 0; for (int i = 0; i < length; i++) { int x = arr[i] - '0'; for (int j = 0; j < m; j++) { next[j] += prev[j]; next[j] %= MOD; next[(j * 10 + x) % m] += prev[j]; next[(j * 10 + x) % m] %= MOD; } if (x == 0) { ans++; } else { next[x % m]++; next[x % m] %= MOD; } int[] tmp = next; next = prev; prev = tmp; Arrays.fill(next, 0); } ans += prev[0]; ans %= MOD; System.out.println(ans); } }