![]() |
VOOZH | about |
Given a positive integer n and the task is to print all the Super-Primes less than or equal to n.
Super-prime numbers (also known as higher order primes) are the subsequence of prime number sequence that occupy prime-numbered positions within the sequence of all prime numbers. The first few super primes are 3, 5, 11, and 17.
Examples:
Input: n = 7
Output: 3 5
Explanation: In list of primes (2, 3, 5, 7}, 3 and 5 are super primes because they appear at 2nd and 3rd positions which are also a prime .Input: n = 17
Output: 3 5 11 17
Explanation: In list of primes (2, 3, 5, 7, 11, 13, 17), 3, 5, 11 and 17 are super primes because they appear at 2nd, 3rd, 5th and 7th positions which are also a prime .
The idea is to generate all the primes less than or equal to the given number n using the Sieve of Eratosthenes. Once we have generated all such primes, we iterate through the array and print all prime number that occupy prime number positions.
3 5 11 17 31 41 59 67 83 109 127 157 179 191 211 241
Time complexity : - O(n*log(log(n)))- Due to the use fo sieve of eratosthenis.
Auxiliary Space:- O(n) - due to the array used to store primes upto n.