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)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
#define ld long double
const ll INF = 1e13;
const ll N = 1e4+5, D=105;
const ll mod= 1e9+7;
/*bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}
*/
string s;
ll d,n,dp[N][D][2];
ll f(ll i, ll sum, bool flag)
{
	if(i==n) return sum==0;
	if(dp[i][sum][flag]!=-1) return dp[i][sum][flag];
	ll &ans = dp[i][sum][flag];
	ans = 0;
	ll l = 0, r=9;
	if(!flag) r = (s[i]-'0');
	loop(dig,l,r+1)
	{
		ll nsum = sum+dig;
		nsum%=d;
		bool nflag = flag||(dig<(s[i]-'0'));
		ans = ans+f(i+1,nsum,nflag);
		ans%=mod;
	}
	return ans;
}
void solve()
{
 cin>>s>>d;
 n=s.size();
 memset(dp,-1,sizeof(dp));
 cout<<(f(0,0,0)-1+mod)%mod;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}