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 <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int dp[10001][101][2],d;
string str;
int rec(int i,int s,int e){
	if(s < 0)
		return 0;
	if(i == str.size()){
		if(s==0)
		return 1;
		return 0;
	}
	if(dp[i][s][e]!=-1)
		return dp[i][s][e];
	int ways = 0;
	if(e){
		for(int j=0;j<=str[i]-'0';j++){
			if(j != str[i]-'0'){
				ways += rec(i+1,(s+j)%d,0);
			}
			else
				ways += rec(i+1,(s+j)%d,1);
			ways %= MOD;
		}
	}
	else{
		for(int j=0;j<=9;j++){
			ways += rec(i+1,(s+j)%d,0);
		}
		ways %= MOD;
	}
	dp[i][s][e] = ways;
	return ways;
}
int32_t main(){

	
	FASTIO;
	mem(dp,-1);
	//string str;
	cin >> str >> d;
	cout << (rec(0,0,1)-1+MOD)%MOD << endl;
    return 0;

}