import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int M = sc.nextInt(); long MOD = (long)Math.pow(10, 9) + 7; int len = s.length(); long[][][] dp = new long[len][M][2]; int first = Integer.parseInt(String.valueOf(s.charAt(0))); if(first == 0) { dp[0][0][0] = 1; } else { dp[0][first % M][1] = 1; dp[0][0][0] = 1; } for(int i = 1; i < len; i++) { int d = Integer.parseInt(String.valueOf(s.charAt(i))); for(int j = 0; j < M; j++) { if(d > 0) dp[i][d % M][1] = (dp[i][d % M][1] + dp[i - 1][j][0]) % MOD; dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j][0]) % MOD; dp[i][(10 * j + d) % M][1] = (dp[i][(10 * j + d) % M][1] + dp[i - 1][j][1]) % MOD; dp[i][(10 * j) % M][1] = (dp[i][(10 * j) % M][1] + dp[i - 1][j][1]) % MOD; } } long ans = 0; long kosuu = 0; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == '0') kosuu++; } ans = (dp[len - 1][0][1] + kosuu) % MOD; System.out.println(ans); } }