Super Prime in c programming

A super-prime number is a prime number that occupies a prime position in the sequence of all prime numbers. For example, if we list all prime numbers as 2, 3, 5, 7, 11, 13, ..., then the super-primes are the primes at positions 2, 3, 5, 7, 11, etc. So 3 (at position 2), 5 (at position 3), and 11 (at position 5) are super-primes.

Syntax

void superPrimes(int n);
bool sieveOfEratosthenes(int n, bool isPrime[]);

Example: Finding Super-Primes Less Than 50

This program uses the Sieve of Eratosthenes to find all primes, then identifies super-primes by checking if the position itself is prime −

#include <stdio.h>
#include <stdbool.h>

void 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 findSuperPrimes(int n) {
    bool isPrime[n + 1];
    sieveOfEratosthenes(n, isPrime);
    
    int primes[n + 1], count = 0;
    
    /* Store all primes in array */
    for (int i = 2; i <= n; i++) {
        if (isPrime[i])
            primes[count++] = i;
    }
    
    printf("Super-primes less than %d are: ", n);
    
    /* Check if position is prime */
    for (int i = 0; i < count; i++) {
        if (isPrime[i + 1])  /* Position i+1 in 1-based indexing */
            printf("%d ", primes[i]);
    }
    printf("<br>");
}

int main() {
    int n = 50;
    findSuperPrimes(n);
    return 0;
}
Super-primes less than 50 are: 3 5 11 17 31 41 

How It Works

  • Step 1: Use Sieve of Eratosthenes to find all prime numbers up to n
  • Step 2: Store all prime numbers in an array
  • Step 3: For each prime at position i, check if position (i+1) is also prime
  • Step 4: If position is prime, the number at that position is a super-prime

Key Points

  • Super-primes are primes located at prime positions in the prime number sequence
  • The first few super-primes are: 3, 5, 11, 17, 31, 41, 59, 67, 83
  • Position counting starts from 1 (3 is at position 2, 5 is at position 3, etc.)

Conclusion

Super-primes represent an interesting subset of prime numbers where both the number and its position in the prime sequence are prime. This concept demonstrates the mathematical beauty of prime number patterns.

Updated on: 2026-03-15T11:28:34+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements