Given a binary number N, and a range represented by L, and R, the task is to convert the given binary number in all the base numbers between L and R (L and R inclusive) and count the resulting prime numbers among them.
Input: N = 111, L = 3, R = 10
When 111 is interpreted in all the base numbers between 3 and 10 we get the resulting numbers as [21, 13, 12, 11, 10, 7, 7, 7], out of which only 5 numbers are prime. Hence, the output is 5.
Input: N = 11, L = 4, R = 19
When 11 is interpreted in all the base numbers between 4 and 19 we get the resulting numbers as 3 which is a prime number. Hence, the output is 16.
Approach: Convert the given binary number to each base between ‘L’ and ‘R’ one by one. Thereafter, check if the resulting number is prime or not. If yes, then increment the count.
Below is the implementation of the above approach: