Prime numbers of the form $(3^n-1)/2$

Recall the factorization $(x^n-1)=(x-1)(1+x+x^2+\cdots x^{n-1})$. Set $x=3^m$ to see that $3^{mn}-1 = (3^m-1)(1+3^m+3^{2m}+\cdots +3^{(n-1)m})$. Since $2$ divides $3^m-1$ this is a factorization of $P_n$ if $3^m-1>2$ and $1+3^m+\cdots+3^{(n-1)m}>1$, which is the case if $m>1$ and $n>1$, therefore $P_{mn}$ is composite if $m>1$ and $n>1$. We can conclude that $P_n$ can only be prime if $n$ is prime.

Given this note that $P_{2n}$ and $P_{5n}$ is composite if $2n$ and $5n$ is composite, which is the case when $n>1$. It only remains to check the case $n=1$, but $P_2=4=2*2$ is not a prime, and $P_5=121=11*11$, so $P_5$ is composite. Kind of interesting that both of $P_2$ and $P_5$ are squares.

Another interesting thing to note when checking primality of $P_q$ for $q$ a prime is that by Fermat's theorem any number dividing $P_q$ must be one more than a multiple of $q$, i.e. if $p|P_q$ then $p=kq+1$ for some integer $k$. Moreover, for odd primes $q$, $k$ would have to be even for $kq+1$ to be odd (since we are looking for an odd prime factor $p$). Therefore we only need to check $2kq+1$. For $q=5$ we have $P_5=121$ and the first primefactor we have to check is 11! $q=7$ gives $P_7=1093$. The smallest prime-factor $p$ of $P_7$ must satisfy $p<\sqrt{P_7}=33.1$, but $2*7+1=15$ is composite, so we only need to check if $4*7+1=29$ divides 1093, which it does not. For $P_{11}=88573$ we need to check divisors up to $\sqrt{P_{11}}=297$. Since we only need to check numbers of the form $22k+1$ it means that at most we will have to check 13 numbers, but in fact $88573=23*3851$, so it is composite.

I wrote a short program to look for prime $P_q$ numbers when $q$ is prime and found the following: $$ \begin{array}{rr|l} q & P_q & \text{prime or composite} \\ \hline 2 & 4 & 2|P_2\\ 3 & 13 & \text{prime}\\ 5 & 121 & 11|P_5\\ 7 & 1,093 & \text{prime}\\ 11 & 88,573 & 23|P_{11}\\ 13 & 797,161 & \text{prime}\\ 17 & 64,570,081 & 1,871 | P_{17}\\ 19 & 581,130,733 & 1,597 | P_{19} \\ 23 & 47,071,589,413 & 47 | P_{23}\\ 29 & 34,315,188,682,441 & 59 | P_{29}\\ 31 & 308,836,698,141,973 & 683 | P_{31} \\ 37 & 225,141,952,945,498,681 & 13,097,927 | P_{37}\\ 41 & 18,236,498,188,585,393,201 & 83 | P_{41}\\ 43 & 164128483697268538813 & 431 | P_{43} \\ 47 & 13294407179478751643893 & 1223 | P_{47}\\ 53 & 9691622833840009948398361 & 107 | P_{53}\\ 59 & 7065193045869367252382405533 & 14425532687 | P_{59}\\ 61 & 63586737412824305271441649801 & 603901 | P_{61}\\ 67 & 46354731573948918542880962705293 & 221101 | P_{67}\\ 71 & 3754733257489862401973357979128773 & \text{prime}\\ 73 & 33792599317408761617760221812158961 & 11243 | P_{73}\\ 79 & 24634804902390987219347201701063882933 & 432853009 | P_{79}\\ 83 & 1995419197093669964767123337786174517613 & 167 | P_{83}\\ 89 & 1454660594681285404315232913246121223340241 & 179 | P_{89}\\ 97 & 9544028161703913537712243143807801346335324481 & 76631 | P_{97}\\ 101 & 773066281098016996554691694648431909053161283001 & 33034273 | P_{101} \\ \end{array} $$ My program ran for a long time for $q=71$. It couldn't decide whether $P_{71}$ is prime.


Hint: Let $q\in\mathbb N, q\neq 1$, then $$ P_q \text{ is composite } \Leftrightarrow \forall n\in\mathbb N: P_{qn} \text{ is composite}$$

In other words, each $q$ you find, such that $P_q$ is not prime (e.g. $q=2,5,11,17,19$) gives you a class $P_{qn}$, which is never prime.


There is a unique factor for every value of $n$ in $b^n-1$. These divide every instance of $b^m-1$ where $n \mid m$. One can see in base 3, that $\frac 12(3^n-1)$ is written as a string of 1's, eg $11111$.

When there is a composite number of 1's it can be written with any of the number's divisors, eg $111111 = 11 * 10101 = 111 * 21$ The unique factor that appears with each prime might be calles an algebraic factor of $b^n-1$

This means that the only rep-units that are prime, are those that have a prime number of digits. Of course, $11$ and $11111$ are both square (2, 11).

We find, eg 3, 7, 13, in this list, as far as $83$. This is the limit of UBASIC at the time the table was prepared.

The program i wrote actually tested the algebraic factors in order of size. The first power is $b^{t(n)}$, where $t(n)$ is the Euler totient of $n$. The next place is sorted by the number of prime divisors of $n$, and any larger powers.

There are many more prime algebraic factors, such as this list (increasing size of prime) 6, 3, 10, 12, 14, 9, 7, 15, 24, 21, 26, 36, 13, 40, 60, 33, 46, 72, 70, 63, 108, 132, 86, 130, 154, 371.