Super Primes

Superprimes are prime numbers that occupy prime numbered positions in the sequence of prime numbers.

Consider the sequence of the first 7 prime numbers: 2, 3 , 5 , 7, 11 , 13, 17 . The numbers in bold are superprimes, because they occupy positions 2, 3, 5, and 7 in the sequence.

3 is the first superprime. What are the last 3 digits of the 142nd superprime?


The answer is 311.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

The 142nd superprime is 6311, and the last 3 digits are 311 .

Write a function that determines whether an integer is prime. Then, iterate through the integers to check if they are prime, and if their position amongst the primes is prime.

# Python solution: SuperPrimes

# There are many methods to determine if a number is prime
# This function uses the Sieve of Eratosthenes
import math
def isPrime(n):
    if (n==1):
        return False
    elif(n<4):
        return True
    elif(n%2==0):
        return False
    elif(n<9):
        return True
    elif(n%3==0):
        return False
    else:
        r = math.floor(math.sqrt(n))
        f = 5
        while (f<=r):
            if (n%f==0):
                return False
            if (n%(f+2)==0):
                return False
            f+=6
        return True

# This function returns the nth superprime
def findSuperPrime(n):
    numSuperPrimes = 0
    numPrimes = 0
    c = 0

    # Iterate until you find n superprimes
    while (numSuperPrimes < n):
        c += 1

        # if c is prime...
        if isPrime(c):
            numPrimes += 1

            #... and its position within the primes is also prime
            if isPrime(numPrimes):

                # then c is a superprime
                numSuperPrimes += 1
    return c

print findSuperPrime(142)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...