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>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
#define int long long
using namespace std;
int dp[10005][2][101];
string s;
int n;
int k;
int rec(int x,bool small,int rem){
    if(x>=n){
       return rem==0?1:0;
    }
    if(dp[x][small][rem]!=-1){
        return dp[x][small][rem];
    }
    //cout<<s[x]<<endl;
    ll sum=0;
    for(int i=0;i<=9;i++){
       // cout<<"oe"<<endl;
        if(!small||i<s[x]-'0'){
            //cout<<"dwf"<<endl;
            sum=(sum+rec(x+1,0,(rem+i)%k))%mod;
        }
        else if(s[x]-'0'==i){
            sum=(sum+rec(x+1,small,(rem+i)%k))%mod;
        }
    }
    return dp[x][small][rem]=sum;
}
signed main(){
    
    SPEED;
    int t=1;
   // cin>>t;
    while(t--){
        cin>>s;
        cin>>k;
        n=s.length();
        memset(dp,-1,sizeof(dp));
        cout<<rec(0,1,0)-1<<endl;
    }   
    return 0;
}