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: Runtime Error)

#include <bits/stdc++.h>
#define int long long int
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int N = 1e6 + 700;
const int mod = 1e9 + 7;
int a , b , k , n;
string lim;
int dp[24][101][2];

int cntDigit(int n){
  if(!n) return 0;
  return 1 + cntDigit(n / 10);
}

int add(int x , int y){
  return ((x % mod) + (y % mod)) % mod;
}
int sub(int x , int y){
  return ((x % mod) - (y % mod) + mod) % mod;
}
int solve(int i , int mod , int flag){
  if(i == n) {
    if(!mod) return 1 ;
    return 0;
  }
  if(dp[i][mod][flag] != -1) return dp[i][mod][flag] ;
  int ans = 0;
  int limit = 9;
  if(!flag){
    limit = lim[i] - '0';
  }
  for(int j = 0 ; j <= limit ; j++){
    int f1 = flag;
    if(!f1 and j < limit) f1 = 1;
    ans = add(ans ,solve(i + 1 , (mod + j) % k , f1));
  }
  dp[i][mod][flag] = ans;
  return ans;
}
 
int32_t main() {    
 L_T_S_K;
 int t = 1; 
// cin >> t;
 while(t--){
  cin >> lim >> k;
  memset(dp , -1 , sizeof dp);
  n = lim.size();
  int p = solve(0 , 0 , 0);
  cout << sub(p , 1) << "\n"; 
 } 
  return 0;
}