Problem:
Score : 100 points

Problem Statement

Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:

The sum of the digits in base ten is a multiple of D.

Constraints

All values in input are integers.

1 \leq K < 10^{10000}

1 \leq D \leq 100

Input

Input is given from Standard Input in the following format:

K
D

Output

Print the number of integers satisfying the condition, modulo 10^9 + 7.

Sample Input 1

30
4

Sample Output 1

6

Those six integers are: 4, 8, 13, 17, 22 and 26.

Sample Input 2

1000000009
1

Sample Output 2

2

Be sure to print the number modulo 10^9 + 7.

Sample Input 3

98765432109876543210
58

Sample Output 3

635270834

Solution in Java (OpenJDK 11.0.6) (judge verdict: Accepted)

import java.util.*;
import java.io.*;
public class Main {
    public static int mod = 1000000007;
    public static long dp[][][] ;
    public static long solve(String k , int D , int pos, int d , int tight){
        if(dp[pos][d][tight] != -1){
            return dp[pos][d][tight];
        }
        int ub = (tight == 1) ? (k.charAt(pos)-'0') : 9;

        if(pos == k.length()-1){
            long ans = 0;
            for(int x = 0 ; x <= ub ; x++)
                if(x%D == d) ans++;
            ans = ans;
            return ans;
        }

        long ans = 0;
        for(int x = 0 ; x <= ub ; x++){
            int forw = ((tight == 1) && (x == ub)) ? 1 : 0;
            ans = (ans + solve(k , D , pos+1 , (d+D-(x%D))%D , forw ))%mod;
        }
        return dp[pos][d][tight] = ans;
    }
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        String k = s.next();
        int D = s.nextInt();
        dp = new long[k.length() + 1][101][2];
        for(int i = 0 ; i <= k.length() ; i++){
            for(int j = 0 ; j <= 100 ; j++){
                for(int l = 0 ; l <= 1 ; l++){
                    dp[i][j][l] = -1;
                }
            }
        }
        long ans = ( mod + (solve(k , D , 0 , 0 , 1)-1)%mod) % mod;
        System.out.println(ans);
    }
}