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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define ll long long
#define pq priority_queue
#define mii map<int,int>

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;

string s;
int d;
int tb[10005][105][2];
vi num;

int dp(int i, int n, int f) {
    if(i == (int)s.size() and n%d == 0) return 1;
    if(i == (int)s.size()) return 0;
    if(tb[i][n][f] != -1) return tb[i][n][f];

    int limit = f == 0 ? num[i] : 9;
    // Se o número formado já é menor que a entrada, podemos colocar qualquer dígito.

    int ans = 0;
    for(int dgt = 0; dgt <= limit; dgt++)
    {
        if(f == 0 and dgt < limit) ans = (ans%oo + dp(i+1, (n%d+dgt%d)%d, 1)%oo)%oo;
        if(f == 0 and dgt == limit) ans = (ans%oo + dp(i+1, (n%d+dgt%d)%d, 0)%oo)%oo;
        if(f == 1) ans = (ans%oo + dp(i+1, (n%d+dgt%d)%d, f)%oo)%oo;  
    }
    tb[i][n][f] = ans % oo;
    return ans % oo;
}

int main() {
    cin >> s >> d;

    
    for(size_t i = 0; i < s.size(); i++)
    {
        num.push_back(s[i] - '0');
    }
    
    memset(tb, -1, sizeof tb);
    printf("%d\n", dp(0, 0, 0)-1);

    return 0;
}