


Input:
'L' = 15 and 'R' = 19
There is only 1 number between which is good,
16 = 1 + 6 = 7 (which is a prime number).
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains two integers ‘L’ and ‘R’.
For each test case, output a single integer denoting the number of good numbers between ‘L’ and ‘R’.
Print the output of each test case in a new line.
You don’t need to print anything. It has already been taken care of. Just implement the given function. 1 is a co-prime number.
1 <= ‘T’ <= 10
1 <= ‘L’, ‘R’ <= 10^5
Time Limit: 1 sec
Algorithm :
The Sum of digits of a number cannot exceed 9*9 for 9 digits, thus we will have to track only 9*9 states which will save time and memory.
We will try to create a function f(x) which returns all good numbers from [0,x]. Later we can use f(R)−f(L−1) to find our answer.
Let's declare our DP as follows: DP[20][2][200]
What does dp[i][tight][sum] even mean?
Base Cases DP[n][0][0] = DP[n][1][0] = 1
We will move from right to left while prepending digits at every index till we finally calculate DP[0][..][..] which denotes the entire input string
What is tight?
We can break DP[i][tight][sum] into subproblems as follows:
// Function to calculate the number of good numbers between 0 to n.