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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Last digit of sum of numbers in the given range in the Fibonacci series
- Count of numbers from the range [L, R] which contains at least one digit that divides K
- Count numbers with unit digit k in given range
- Sum of all the prime numbers in a given range
- Prime numbers in a given range using STL | Set 2
- Count of Numbers in a Range where digit d occurs exactly K times
- Count of numbers in range which are divisible by M and have digit D at odd places
- Print prime numbers in a given range using C++ STL
- Sum of all prime divisors of all the numbers in range L-R
- K-Primes (Numbers with k prime factors) in a range