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: Accepted)

//In The Name of Beauty
//...So here I go is my shot
//Feet fail me not 'cause maybe the only opportunity that I got...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e4 + 8;
ll const KAM  = 1e2 + 8;
ll const delta = 1000000007;
ll dp[MAXN][KAM];
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    string k;
    cin >> k;
    ll d;
    cin >> d;
    dp[0][0] = 1;
    for(ll i = 0;i < MAXN - 1;i++)
    {
        for(ll j = 0;j < d;j++)
        {
            for(ll k = 0;k < 10;k++)
            {
                dp[i + 1][(k + j) % d] = (dp[i + 1][(k + j) % d] + dp[i][j]) % delta;
            }
        }
    }
    ll ans = 0;
    ll temp = 0;
    for(ll i = 0;i < k.size();i++)
    {
        for(ll j = (k[i] - '0') - 1;j >= 0;j--)
        {
            ans = (ans + dp[k.size() - i - 1][(d - (temp + j) + d) % d]) % delta;
        }
        temp = (temp + (k[i] - '0')) % d;
    }
    if(temp % d != 0)ans = (ans - 1 + delta) % delta;
    cout << ans;
    return 0;
}
//Written by M_H_H_7