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>

typedef long long ll;

using namespace std;

const int maxn = 1e4 + 100, maxl = 110, dig = 10, mod = 1e9 + 7;
ll dp[maxn][maxl], ps[maxn][maxl];

int main()
{
    int d;
    string k;
    cin >> k >> d;

    for (int i = 0; i < maxn - dig; i++)
        for (int j = 0; j < d; j++)
            for (int x = 0; x < dig; x++)
                if (!i)
                    dp[i + 1][j] += (((x % d) == j) && x);
                else
                    dp[i + 1][(j + x) % d] = (dp[i + 1][(j + x) % d] + dp[i][j]) % mod;

    for (int j = 0; j < d; j++)
        for (int i = 1; i < maxn - dig; i++)
            ps[i][j] = ps[i - 1][j] + dp[i][j];

    ll ans = 0, s = 0, x;
    for (int i = 0; i < k.size(); s += x, i++)
    {
        x = k[i] - '0';

        if (i == k.size() - 1)
            for (int j = 0; j <= x; j++)
                ans += !((s + j) % d);
        else
            for (int j = 0; j < x; j++)
                ans = (ans + ps[k.size() - i - 1][(maxn * dig * d - s - j) % d] + ((!((s + x) % d)) && (j || i))) % mod;
    }

    cout << (ans) % mod;

    return 0;
}