How many PR numbers exist in a given range?

348 Views Asked by At

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 properties: -

1) :- No pair of adjacent digits are co-prime i.e. adjacent digits in a PR number will not be co-prime to each other.

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

Note:- Two numbers 'a' and 'b' are co-prime , if gcd(a,b)=1 .

Also, gcd(0,a)=a;

Example:- [2,5].

Output:- '4'.

(Note '1' : - '1' is not a prime-number,though its very common)

(All the integers:- '2','3','4','5') satisfy the condition of PR numbers :-)

What can be the the most efficient algorithm to solve this ?