

Given:
‘L’ = 1, ‘R’ = 23, ‘K’ = 6.
The answer will be 3 since there are three numbers between 1 and 23 whose product of digits is 6, and those are 6, 16, and 23.
The first line of input contains an integer ‘T’ denoting the number of test cases.
Next, ‘T’ lines consist of three space-separated integers, ‘L’, ‘R’, ‘K’.
For each test case, return the count of numbers between ‘L’ and ‘R’ whose product of digits is ‘K’.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 10
1 <= ‘L’ <= 10 ^ 8
‘L’ <= ‘R’ <= 10 ^ 8
1 <= ‘K’ <= 10 ^ 4
Time Limit: 1sec.
The idea is to traverse from ‘L’ to ‘R’ and check for each number if the product of the digits of the number is equal to ‘K’.
The steps are as follows:
The idea is to observe that the answer is :
Count of numbers that satisfy conditions from 0 to ‘R’ - Count of numbers that satisfy conditions from 0 to ‘L - 1’.
This can be done by calculating these two quantities separately and then returning the answer. Since we are using recursion, our states will depend on the following parameters:
The steps are as follows:
The idea is to observe that the answer is :
Count of numbers that satisfy conditions from 0 to ‘R’ - Count of numbers that satisfy conditions from 0 to ‘L - 1’.
This can be done by calculating these two quantities separately and then returning the answer. Since we are using recursion, our states will depend on the following parameters:
We can see that since there are multiple states, there will be repeated sub-problems for which we recur repeatedly, therefore to speed up recursion we can hash repeating sub-problems by maintaining a ‘dp’ array which stores the answer for given states.
The steps are as follows: