

Forgiven A = 10, B = 15 and K = 2.
12 and 14 are magical numbers because the sum of digits of 12 and 14 is a prime number, also 12 and 14 both are divisible by 2.
The first line of input contains an integer ‘T’, denoting the number of test cases. Then each test case follows.
The first and the last line of each test case contains three space-separated integers denoting ‘A’, ‘B’, and ‘K’.
For each test case, print a single line containing one integer, denoting the number of Magical Numbers between ‘A’ and ‘B’(inclusive)
The output of each test case will be printed on a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= A <= B <= 10^9
1 <= K <= 100
Time Limit: 1 sec.
Let, magicalNumbers(x, y) = magical number between x and y(inclusive)
Then, magicalNumbers(A, B) = magicalNumbers(1, B) - magicalNumbers(1, A -1).
Let's solve the above two sub-problem magicalNumbers(1, X) individually,
The idea is to use digit - dp.
Consider the global array isPrime [130 ], if ‘i’ is prime then isPrime[ i ] = 1 else 0 and 4D array for memoization ‘dp[13][130][1005][3]’.
The ‘helper’ function returns the number of magical numbers which are less than or equal to the sequence of numbers in the ‘vec’ array. It takes four-parameter (‘vec’, current index, the sum of digits till current index, the remainder of a sequence of the number formed till current index, ‘K’, ‘isSmall’ variable if it is 1, means current sequence of numbers are smaller than the given sequence in ‘vec’ else equal.