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>
using namespace std;
#define ll              long long 
#define int             ll
#define ff              first
#define ss              second
#define pb              emplace_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define forr(i, a, b)   for(int i =int(a);i<=int(b);i++)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
    template <typename Arg1>
     void __f(const char* name,Arg1&& arg1){
        cout<<name<<" : "<<arg1<<std::endl;
     }
     template <typename Arg1, typename... Args>
     void __f(const char* names,Arg1&& arg1,Args&&... args){
        const char* comma = strchr(names+1 ,',');
        cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
     }
#else
#define trace(...)
#endif
/*     
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
double pi = 2.0*acos(0);
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}

///////////////////////////////////////////////////////////////////////////////////////////////

string k;int D;
int n;
int m = 1e9+7;
int dp[100001][2];
int solve(int pos,int tight,int sum){
      
      if(pos == n)
      {
          if(sum%D == 0 && sum>0)
            return 1;
          else
            return 0;
      }

      if(dp[pos][tight]!= -1)
        return dp[pos][tight];

      int res = 0;

      int newtight;
      int lim = (tight)?(k[pos]-'0'):9;

      for(int i = 0;i<=lim;i++)
      {
          newtight = (tight==1 && i==lim)?1:0;

          res = (res%m+ solve(pos+1,newtight,(sum+i))%m)%m;
      }

      return dp[pos][tight] = res;

}


signed main(void)
{
      fast();
      //w(t)
      cin>>k>>D;
      n = (int)k.length();
      for(int  i =0;i<=n;i++)
        {dp[i][0] = -1;dp[i][1] = -1;}

      cout<<solve(0,1,0)<<endl;

}