PR Numbers

3.9

18 votes
Dynamic Programming, gcd, dp on digits, digit dp, Greatest common divisor, medium, Algorithms, Easy-Medium, Digit DP, arithemtic operations, Greatest common divisor, Dynamic programming
Problem

You are given 2 integers L and R. You are required to find the count of all the PR numbers in the range L to R inclusively. PR number are the numbers which satisfy following 2 properties: -

P :- No pair of adjacent digits are coprime i.e. 2 adjacent digits in a PR number will not be coprime to each other.

R :- PR number is divisible by all the single digit prime numbers which occur as a digit in the PR number.

Input Format

The first line contains 2 space seperated integers L and R (1L,R1018).

Output Format

Print answer for each test case in a new line.

Sample Input
2 5
Sample Output
4
Time Limit: 1
Memory Limit: 500
Source Limit:
Explanation

Numbers 2,3,4 and 5 satisfy the condition. Hence the answer is 4.

Editor Image

?