Super-prime numbers (also known as higher order primes) are the subsequence of prime numbers that occupy prime-numbered positions within the sequence of all prime numbers. First few Super-Primes are 3, 5, 11 and 17.
The task is to print all the Super-Primes less than or equal to the given positive integer N.
Input: 7 Output: 3 5 3 is super prime because it appears at second position in list of primes (2, 3, 5, 7, 11, 13, 17, 19, 23, ...) and 2 is also prime. Similarly 5 appears at third position and 3 is a prime. Input: 17 Output: 3 5 11 17
The idea is to generate all the primes less than or equal to the given number N using Sieve of Eratosthenes. Once we have generated all such primes, we iterate through all numbers and store it in the array. Once we have stored all the primes in the array, we iterate through the array and print all prime number which occupies prime number position in the array.
Super-Primes less than or equal to 241 are : 3 5 11 17 31 41 59 67 83 109 127 157 179 191 211 241
This article is contributed by Rahul Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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 the super power of a given Number
- Print the nearest prime number formed by adding prime numbers to N
- Quick ways to check for Prime and find next Prime in Java
- Print prime numbers with prime sum of digits in an array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find coordinates of a prime number in a Prime Spiral
- Check whether the sum of prime elements of the array is prime or not
- Sum of each element raised to (prime-1) % prime
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Prime numbers after prime P with sum S
- Right-Truncatable Prime
- Check n^2 - m^2 is prime or not
- Sum of the first N Prime numbers
- Balanced Prime
Improved By : Mithun Kumar