I searched for primes of the form $p^p+2$, where $p$ is prime for a range of $p \le 10^5$ on PARI/GP and found that 29 is the only prime of this form in this range.


$(1)$ Is $29$ the only prime of the form $p^p+2$, where $p$ is prime?

$(2)$ If not, then are there a finite number of primes of the form $p^p+2$? Can you prove/disprove this?

Edit: Since $p^p$ grows really fast and primes get rarer and are spread farther out for large numbers,

I conjecture that $29$ is the only prime of the form $p^p+2$ where $p$ is a prime.

  • 2,367
  • 10
  • 34
  • 3
    I think (2) is likely. maybe (1) as well, and hard to decide. Primes are rare far out, and $p^p$ grows rapidly. Did the question occur to you for any reason other than random curiousity ? – Ethan Bolker May 08 '19 at 21:09
  • 2
    @EthanBolker Well I like trying to find rare primes, and since $p^p$ grows rapidly I figured primes like that were rare. But still it would be really nice to prove that 29 is the only prime of this form – Mathphile May 08 '19 at 21:14
  • 12
    @Mathphile For $p=239$ , there is no small factor. So, there is no easy way to show that $p=3$ is the only soluton, if this is actually the case. Did you really arrive at $p=10^6$ ? The number $p^p+2$ is huge for primes near $10^6$. – Peter May 08 '19 at 21:29
  • 3
    I would guess that there are only a finite number of primes. There are about a $(p \log^2 p)^{-1}$-fraction of numbers of size roughly $p^p$ that are prime, by the Prime Number Thm. So--making some leaps of logic admittedly--it is tempting to say that the number of primes of this form is something like $\sum_{p} (p \log^2 p)^{-1}$ which is bounded – Mike May 08 '19 at 22:09
  • Looking at factorisations those numbers tend to be square free more often than just luck. – Radost May 09 '19 at 00:30
  • 1
    Neither $3$ is square module $29$ nor $29$ is square modulo $3$. Would this be a necessary condition? Or perhaps that the two primes are or are not simultaneously quadratic residue one of the other? – Piquito May 09 '19 at 00:48
  • @Piquito good observation! – Mr Pie May 15 '19 at 18:39
  • @Piquito note that $p$ is a square mod $q$ iff $-2$ is. The latter means $q\equiv 1,3\pmod 8$. Then $q$ is a non-square mod $p$ if $q\eqiuv p\equiv 3\pmod 4$ – Hagen von Eitzen May 19 '19 at 15:42

3 Answers3


With pfgw, I checked $$p^p+2$$ for the primes from $\ 3\ $ to $\ 24\ 001\ $ The only prime occured for $\ p=3\ $ Hence if another prime of this form exist, it must have more than $\ 100\ 000\ $ digits

  • 78,494
  • 15
  • 63
  • 194
  • 1
    What is hardware configuration on which you are able to check primality of 100000 digit numbers? – Nilotpal Sinha May 09 '19 at 08:09
  • 4
    The program pfgw is specially designed for testing huge numbers for primality. I used the default trial division. I also doublechecked with factordb. Upto $p=20\ 000$ , no other prime. – Peter May 09 '19 at 08:22
  • So you ran the program on normal laptop? I mean what was the configuration and runtime? – Nilotpal Sinha May 09 '19 at 08:24
  • 2
    On a normal PC. No special hardware. It took several hours however on my slow computer. – Peter May 09 '19 at 08:25
  • 1
    now with my information linked you might be able to push that into millions. –  May 09 '19 at 19:24
  • @RoddyMacPhee For this, my hardware is too poor. With a good computer and much patience, everyone can continue the check upto $10^6$ or $10^7$ – Peter May 09 '19 at 19:52
  • For what I did in that link, I mostly used pen and paper and the online version og PARI/GP. –  May 09 '19 at 19:57

Some working, but no solution:

Note that $p=2$ doesn't work, and $p=3$ does work. Now suppose $p > 3$.

Suppose $p \equiv 1 \pmod{3}$. Then $p^p + 2 \equiv 1^p + 2 \equiv 0 \pmod{3}$, so it isn't prime.

Therefore, $p \equiv -1 \mod{3}$ and $p$ odd so $p \equiv -1 \mod{6}$. This is as far as I could get. Using WolframAlpha for this case yields numbers that do not have many prime factors, and these factors being distinct and large, so I don't see any way to progress from here.

Nilotpal Sinha
  • 15,471
  • 4
  • 26
  • 73
Sharky Kesa
  • 2,673
  • 8
  • 21

It seems reasonable to expect that 29 is the only prime, just because primes get rare as numbers get big, so we'd expect almost all of these numbers to be composite.

That is, heuristically, the prime number theorem gives us the "probability" that a number $n$ is prime is about $\frac{1}{\ln(n)}$.

Therefore, the expected number of primes of this form should be $$ \sum_p \frac{1}{\ln(p^p + 2)} < \sum_p \frac{1}{p \ln(p)} $$ where the sum is over all odd primes. This latter sum converges, as shown in $\sum_{p \in \mathcal P} \frac1{p\ln p}$ converges or diverges?, to roughly 0.92 (the sum over all primes is less than 1.64; the sum over all odd primes omits the term $\frac{1}{2\ln(2)}$.)

So, we'd "expect" to find about one prime of this form, and we have.

Of course, this isn't a proof; it assumes that numbers of the form $p^p + 2$ behave "randomly" with respect to prime factorization, rather than the factors having some special properties.

(Note that applying the same argument to numbers of the form $n^n + 2$, without the requirement that $n$ be prime, gives an expected number of primes approximately $\sum \frac{1}{n\ln(n)}$, which is infinite. Indeed, there are already 5 examples before 2000, at $n = 0, 1, 3, 737, 1349$.)

Compare Hardy and Littlewood's Conjecture E in Some problems of ‘Partitio numerorum’; III: On the expression of a number as a sum of primes:

There are infinitely many primes of the form $m^2 + 1$. The number $P(n)$ of such primes less than $n$ is given asymptotically by $$P(n) \sim C \frac{\sqrt{n}}{\ln(n)}$$ where $$C = \prod_{p=3}^\infty \Biggl(1 - \frac{1}{p-1}\biggl(\frac{-1}{p}\biggr)\Biggr).$$

Also Conjecture K, which gives an aysmptotic number of primes of the form $m^3 + k$ for any fixed $k$ (except when $k$ is a cube).

Nick Matteo
  • 8,583
  • 2
  • 22
  • 52