For all $m$ there exist $n$ s.t. both $3^in\pm2$ are primes for all $i<m$?

I came up with the following question with a game. The game says:

Start with an odd number $n$ greater than 3. In each turn, check if its adjecent odd numbers are primes. If the left one is a prime, the add it to $n$, or take it away from $n$. So does the right one.

And that means:

  • $n\pm2\text{ are both primes}\iff n\to3n$
  • $n+2\text{ is a prime and }n-2\text{ is not a prime}\iff n\to n+4$
  • $n+2\text{ is not a prime and }n-2\text{ is a prime}\iff n\to n-4$
  • $n\pm2\text{ are neither primes}\iff n\to-2n\text{, that means the game ended}$

If $n$ is the mutiple of 3, $n>3$ so $n$ and $n\pm6$are't primes. And if one of $n\pm2$ is prime, for example, $n+2$, Then the game would be like: $n\to n+4\to n\to n+4\to\cdots$. That means if $n$ escapes tripling, it will be in the above loop.

I want to know the biggest ratio between the initial $n$ and the biggist $n$ it can reach. That might be: $n\to n+4\to3(n+4)\to3^2(n+4)\to3^3(n+4)\to\cdots\to3^m(n+4)\to3^m(n+4)+4$. That means, for $i=0,1,2,3,\cdots,n-1$,$3^i(n+4)\pm2$ should be prime. Let $n^\prime=n+4$,And that's the question I ask.

With the help of the following Python program, I can know the smallest $n$ for $m=3$ is $5$, and the smallest $n$ for $m=4$ is $1547805$. I wondered if there exist $n$ for any $m$ beyond $4$.

def isprime(x):
    for i in range(2, int(x ** 0.5) + 2):
        if x % i == 0:
            return False
    return True
a = 0
i = 5
while True:
    j = i
    b = 0
    while True:
        if not isprime(j - 2) or not isprime(j + 2):
        j *= 3
        b += 1
    if a < b:
        a = b
        print(i, b)
    i += 2
  • 2
    $\begingroup$ In the question at the top, do you mean $n \cdot 3^i \pm 2$ instead of just $3^i \pm 2$? $\endgroup$ Jun 19, 2021 at 7:10
  • $\begingroup$ @ravi-fernando Thanks. The original question is wrong. I've just fixed it. $\endgroup$ Jun 19, 2021 at 9:40
  • 1
    $\begingroup$ You talk about what happens for $k=3$ and for $k=4$, but $k$ doesn't appear anywhere else in the question, so what is it meant to be? $\endgroup$ Jun 19, 2021 at 12:39
  • 1
    $\begingroup$ @GerryMyerson It's my mistake. $k$ must be $m$. $\endgroup$ Jun 19, 2021 at 23:19
  • 2
    $\begingroup$ If this is true for all $m$, it would imply there are infinitely many pair of primes with a distance of at most $4$. The smallest distance such a claim is currently known for is (I believe) $246$, due to the Polymath8 project. $\endgroup$ Jun 19, 2021 at 23:31

2 Answers 2


Assuming Schinzel's hypothesis H (a widely believed conjecture), there does exist such an $n$ for any given $m$. Proof: given $m$, consider the polynomials \begin{align*} f_1(x) & = x-2, \\ f_2(x) & = x+2, \\ f_3(x) & = 3x-2, \\ f_4(x) & = 3x+2, \\ & \vdots \\ f_{2m+1}(x) & = 3^m x-2, \text{and} \\ f_{2m+2}(x) & = 3^m x+2. \end{align*} They're all irreducible (since they're linear), and they have positive leading coefficients. Moreover, I claim there is no single prime $p$ with the property that for all $n \in \mathbb Z$, $p$ divides one of the $f_i(n)$. Indeed, if $p$ is odd, then it doesn't divide any of the $f_i(0) = \pm 2$; if $p = 2$, then it doesn't divide any of the $f_i(1)$.

According to Schinzel's hypothesis H, then, there should be infinitely many $n \in \mathbb Z$ such that all of the $f_i(n)$ are prime.

Having said that, we definitely can't prove this unconditionally at our current state of knowledge, since (as was pointed out in the comments) it would imply the existence of infinitely many pairs of cousin primes.

  • $\begingroup$ Excellent answer (+1) ! $\endgroup$
    – Peter
    Jun 20, 2021 at 8:01

$$n=78\ 440\ 800\ 515$$ gives prime pairs for $i=0,1,2,3,4$. This should be the smallest such $n$.

With the following PARI/GP routine, you can extend the search.

gp > maxi=0;forstep(j=1155,10^13,2310,k=0;while(ispseudoprime(3^k*j-2)+ispseudoprime(3^k*j+2)==2,k=k+1);k=k-1;if(k>maxi,maxi=k;print(j,"   ",k)))
243705   1
282975   2
334315905   3
78440800515   4
gp >

The program only considers numbers of the form $2310\cdot s+1155$ , so only the output for $k=4$ (corresponding with $m=5$) is meaningful for the question. But for $k\ge 4$ ($m\ge 5$), this form ($2310\cdot s+1155$) is necessary. The program shows that for $k\ge 5$ ($m\ge 6$) , $n$ must exceed $10^{13}$.

  • $\begingroup$ Product of all primes that have 3 as a generator ? $\endgroup$ Jun 19, 2021 at 19:14
  • $\begingroup$ Great! Can you tell me how do you calculate it? Also, I want to know if there exist n for any m - another typing error:( $\endgroup$ Jun 19, 2021 at 23:22
  • 1
    $\begingroup$ @Alex-Github-Programmer Basically with brute force. But solutions for $m\ge 5$ must be of the form $2310\cdot s+1155$ (We can easily show that $n$ must have the prime factors $3,5,7,11$ and of course , $n$ must be odd). The below answer gives indication that there is no limit for $m$, it will of course become more and more difficult to find solutions. I currently run a routine to search for even better solutions. $\endgroup$
    – Peter
    Jun 20, 2021 at 8:04
  • $\begingroup$ If I find a solution for $m\ge 6$, I will update my answer. $\endgroup$
    – Peter
    Jun 20, 2021 at 8:06
  • $\begingroup$ If $3$ is a generator mod $p$ it must be a factor of $n$ to possibly exceed $p-1$ . And so must $p$ such that $3$ generates $\pm 2$ $\endgroup$ Jun 20, 2021 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.