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.
Approch: 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:
- Converting a Real Number (between 0 and 1) to Binary String
- Given a number N in decimal base, find number of its digits in any base (base b)
- Count number of primes in an array
- Count primes that can be expressed as sum of two consecutive primes and 1
- Count of primes below N which can be expressed as the sum of two primes
- Find the Nth digit from right in base B of the given number in Decimal base
- Given a number N in decimal base, find the sum of digits in any base B
- Count the number of primes in the prefix sum array of the given array
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count of all values of N in [L, R] such that count of primes upto N is also prime
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count Primes in Ranges
- Check if all nodes of the Binary Tree can be represented as sum of two primes
- Count of interesting primes upto N
- Maximum count of common divisors of A and B such that all are co-primes to one another
- Count numbers which can be represented as sum of same parity primes
- Length of largest sub-array having primes strictly greater than non-primes
- Count of integers up to N which represent a Binary number
- Count number of binary strings without consecutive 1's
- Count number of binary strings of length N having only 0's and 1's
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.