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.-
- Super Ugly Number (Number whose prime factors are in given set)
- Difference between super() and this() in java
- super and this keywords in Java
- Super Keyword in Java
- JS++ | Access Modifiers and 'super'
- Accessing Grandparent’s member in Java using super
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- DBMS | Keys in Relational Model (Candidate, Super, Primary, Alternate and Foreign)
- Project Idea | (Optimization of Object-Based Image Analysis with Super-Pixel for Land Cover Mapping)
- Print the nearest prime number formed by adding prime numbers to N
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- 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
Improved By : Mithun Kumar