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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Count of N-digit numbers having digit XOR as single digit
- 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
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Count all prime numbers in a given range whose sum of digits is also prime
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Highest power of 2 that divides the LCM of first N Natural numbers.
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Count n digit numbers not having a particular digit
- Find all array elements occurring more than ⌊N/3⌋ times
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- C/C++ Program to find Prime Numbers between given range