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)

//be name khoda
#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const ll maxn = 1e5+10;
const ll K = 510;
const ll mod = 1e9+7;

ll n , m , k, d;
ll dp[maxn][K], f[maxn][K];
string s;

int main()
{
    cin>> s >> d; n = s.size();

    for(ll i = n-1; i >= 0; i--)
        for(ll j = 0; j < d; j++)
        {
            if(i == n-1){
                for(ll ii = 0; ii < 10; ii++)
                    if((ii % d) == j)
                        f[i][j]++;
                continue;
            }
            for(ll ii = 0; ii < 10; ii++){
                ll x = (j-ii+d)%d;
                f[i][j] += f[i+1][x]; f[i][j] %= mod;
            }
        }

    for(ll i = n-1; i >= 0; i--)
    {
        ll y = s[i]; y -= 48;
        for(ll j = 0; j < d; j++)
        {
            if(i == n-1){
                for(ll ii = 0; ii <= y; ii++)
                    if((ii % d) == j)
                        dp[i][j]++;
                continue;
            }

            for(ll ii = 0; ii < y; ii++){
                ll x = (j-ii+d)%d;
                dp[i][j] += f[i+1][x]; dp[i][j] %= mod;
            }
            ll x = (j-y+d)%d;
            dp[i][j] += dp[i+1][x]; dp[i][j] %= mod;
        }
    }

    cout<< (dp[0][0] - 1 + mod) % mod;
}