Super-prime numbers (also known as higher-order primes or prime-indexed primes) are the subsequence of prime numbers that occupy prime-numbered positions within the sequence of all prime numbers. The subsequence begins:
1 | 3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, 211, 241, 277, 283, 331, 353, 367, 401, 431, 461, 509, 547, 563, 587, 599, 617, 709, 739, 773, 797, 859, 877, 919, 967, 991, ... |
Example: find super prime in c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include<iostream> using namespace std; bool SieveOfEratosthenes(int n, bool isPrime[]) { isPrime[0] = isPrime[1] = false; for (int i=2; i<=n; i++) isPrime[i] = true; for (int p=2; p*p<=n; p++) { if (isPrime[p] == true) { for (int i=p*2; i<=n; i += p) isPrime[i] = false; } } } void superPrimes(int n) { bool isPrime[n+1]; SieveOfEratosthenes(n, isPrime); int primes[n+1], j = 0; for (int p=2; p<=n; p++) if (isPrime[p]) primes[j++] = p; for (int k=0; k<j; k++) if (isPrime[k+1]) cout << primes[k] << " "; } int main() { int n = 343; cout << "Super-Primes less than "<< n << " are :"<<endl; superPrimes(n); return 0; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.