import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final char[] S = sc.next().toCharArray(); final int M = sc.nextInt(); final long MOD = 1000000007; long[] mods = new long[M + 1]; mods[0] = 1; int zero_count = 0; long[] next_tmp = new long[M + 1]; for(int cur = 0; cur < S.length; cur++){ final int cur_num = Character.getNumericValue(S[cur]); Arrays.fill(next_tmp, 0); if(cur_num == 0){ zero_count++; } for(int mod = (cur_num != 0 ? 0 : 1); mod <= M; mod++){ if(mods[mod] == 0){ continue; } final int next_mod = (mod * 10 + cur_num) % M; if(next_mod == 0){ next_tmp[M] += mods[mod]; next_tmp[M] %= MOD; }else{ next_tmp[next_mod] += mods[mod]; next_tmp[next_mod] %= MOD; } } for(int i = 0; i <= M; i++){ mods[i] += next_tmp[i]; mods[i] %= MOD; } } System.out.println((mods[M] + zero_count) % MOD); } }