The ultimate primes

What is the 27th value of n n such that 2 n 3 2^{n}-3 is a prime number?


The answer is 850.

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.

5 solutions

Beakal Tiliksew
Aug 13, 2015

Using Miller–Rabin primality test in conjunction with sieve we can efficiently find the value of n n .

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
def primesbelow(n):#Sieve method

    #""" Input n>=6, Returns a list of primes, 2 <= p < n """
    correction = n % 6 > 1
    n = {0:n, 1:n-1, 2:n+4, 3:n+3, 4:n+2, 5:n+1}[n%6]
    sieve = [True] * (n // 3)
    sieve[0] = False
    for i in range(int(n ** .5) // 3 + 1):
        if sieve[i]:
            k = (3 * i + 1) | 1
            sieve[k*k // 3::2*k] = [False] * ((n//6 - (k*k)//6 - 1)//k + 1)
            sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((n // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
    return [2, 3] + [(3 * i + 1) | 1 for i in range(1, n//3 - correction) if sieve[i]]

smallprimeset = set(primesbelow(100000))
_smallprimeset = 100000

def isprime(n, precision=7):#Miller-Rabin

    if n == 1 or n % 2 == 0:
        return False
    elif n < 1:
        raise ValueError("Out of bounds, first argument must be > 0")
    elif n < _smallprimeset:
        return n in smallprimeset


    d = n - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1

    for repeat in range(precision):
        a = random.randrange(2, n - 2)
        x = pow(a, d, n)

        if x == 1 or x == n - 1: continue

        for r in range(s - 1):
            x = pow(x, 2, n)
            if x == 1: return False
            if x == n - 1: break
        else: return False

    return True

print( [i for i in range(2,1000) if isprime((2**i)-3)])

Maria Kozlowska
Aug 14, 2015

Quick way to check it is: OEIS A050414

Kaleab Belete
Feb 1, 2016

@Beakal Tiliksew 200+ digit solutions are a bit unfair for those of us using C++, don't you think?

hey @Kaleab Belete , It will still work on C++ though. The 200+ digit is hardly significant for the problem.

Beakal Tiliksew - 5 years, 4 months ago

Log in to reply

Yeah but you have to use arbitrary precise arithmetic libraries nonetheless. I'm guessing python doesn't have such limitations...

Kaleab Belete - 5 years, 4 months ago

Log in to reply

Not really here is a c++ program for miller-rabin.. You can look more on how it works here .

Beakal Tiliksew - 5 years, 4 months ago
Pratik Sapre
Sep 25, 2015
 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
import java.util.*;
import java.math.*;

public class Main
{
    public static void main(String[] args)
    {
        int n=2;
        int count=0;
        BigInteger num = new BigInteger("0");
        BigInteger TWO = new BigInteger("2");
        BigInteger THREE = new BigInteger("3");
        for(;;)
        {
            num= ((TWO).pow(n)).subtract(THREE);
            if(num.isProbablePrime(64000))
            {count++;
            }

            if(count==27)
            {break;}
            n++;

        }

        System.out.println("N="+n);
        }

} 

Output: N=850

Bill Bell
Aug 18, 2015

Quicker than trying to find this is oeis.org. (That would be my usual dodge.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from gmpy2 import is_prime

n=1
count=0
while True:
    if is_prime(2**n-3):
        count+=1
        if count==27:
            print n
            break
    n+=1

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...