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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new KK(); }
class KK
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	public const int MOD = 1000000007;
	public const long INFL = 4011686018427387913L;
	public KK()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	string K;
	int D;
	void Solve()
	{
		K = Str;
		D = F;
		dp = new long[K.Length + 1, 2, D];
		done = new bool[K.Length + 1, 2, D];
		WriteLine(Calc() - 1);
	}
	long[,,] dp;
	bool[,,] done;
	long Calc(int k = 0, bool t = true, int s = 0)
	{
		var t2 = t ? 1 : 0;
		if (!done[k, t2, s])
		{
			done[k, t2, s] = true;
			if (k == K.Length) dp[k, t2, s] = s == 0 ? 1 : 0;
			else
			{
				var x = K[k] - '0';
				var r = t ? x : 9;
				for (var i = 0; i <= r; ++i) dp[k, t2, s] = (dp[k, t2, s] + Calc(k + 1, t && i == r, (s + i) % D)) % MOD;
			}
		}
		return dp[k, t2, s];
	}
}