Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Prime Digit Sum

Hard
0/120
Average time to solve is 45m
profile
Contributed by
2 upvotes
Asked in companies
OracleTCSCodenation

Problem statement

Find the number of good numbers between two numbers ‘L’ and ‘R’ inclusive. A number is good if the sum of its digits is a prime number

Output the number of good numbers.

Example :
Input:
'L' = 15 and 'R' = 19
There is only 1 number between which is good,
16 = 1 + 6 = 7 (which is a prime number).
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= ‘T’ <= 10 
1 <= ‘L’, ‘R’ <= 10^5

Time Limit: 1 sec
Sample Input 1 :
2
5 11
1 20
Sample Output 1 :
3
9   
Explanation Of Sample Input 1 :
For test case 1 we have, 

5 , 7 ,
11 = 1+1 = 2
As 2, 5, 7 are prime numbers so 5, 7, 11 are good.

For test case 2 we have,

2, 3, 5, 7,
11 = 1 + 1 = 2
12 = 1 + 2 = 3
14 = 1 + 4 = 5   
16 = 1 + 6 = 7
20 = 2 + 0 = 2
As 2, 3, 5, 7 are prime numbers so 2, 3, 5, 7, 11, 12, 14, 16, 20 are good.
Sample Input 2 :
2
12 16
9 19
Sample Output 2 :
3
4  
Full screen
Console