import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { 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[2][M + 1]; mods[0][0] = 1; int zero_count = 0; for(int cur = 0; cur < S.length; cur++){ final int turn = cur % 2; final int cur_num = Character.getNumericValue(S[cur]); if(cur_num == 0){ zero_count++; } for(int i = 0; i <= M; i++){ mods[1 - turn][i] = mods[turn][i]; } for(int mod = (cur_num != 0 ? 0 : 1); mod <= M; mod++){ if(mods[turn][mod] == 0){ continue; } final int next_mod = (mod * 10 + cur_num) % M; if(next_mod == 0){ mods[1 - turn][M] += mods[turn][mod]; mods[1 - turn][M] %= MOD; }else{ mods[1 - turn][next_mod] += mods[turn][mod]; mods[1 - turn][next_mod] %= MOD; } } } System.out.println((mods[S.length % 2][M] + zero_count) % MOD); } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public void close() throws IOException { br.close(); } } }