Given a range L to R, the task is to find the highest occurring digit in prime numbers lie between L and R (both inclusive). If multiple digits have same highest frequency print the largest of them. If no prime number occurs between L and R, output -1.
Input : L = 1 and R = 20. Output : 1 Prime number between 1 and 20 are 2, 3, 5, 7, 11, 13, 17, 19. 1 occur maximum i.e 5 times among 0 to 9.
The idea is to start from L to R, check if the number is prime or not. If prime then increment the frequency of digits (using array) present in the prime number. To check if number is prime or not we can use Sieve of Eratosthenes.
Below is the implementation of this approach:
This article is contributed by >Anuj Chauhan(anuj0503). 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Count of Numbers in Range where first digit is equal to last digit of the number
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Count numbers with unit digit k in given range
- Count of Numbers in a Range where digit d occurs exactly K times
- Sum of all the prime numbers in a given range
- Prime numbers in a given range using STL | Set 2
- Print prime numbers in a given range using C++ STL
- Sum of all prime divisors of all the numbers in range L-R
- Count numbers from range whose prime factors are only 2 and 3
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Sum of numbers in a range [L, R] whose count of divisors is prime
- K-Primes (Numbers with k prime factors) in a range
- Find the occurrences of digit d in the range [0..n]
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime