MethodMath
Ask
Join
HomeTopicsAskAlerts
Profile

© 2026 MethodMath. Built for mathematical knowledge sharing.

AboutContactGuidelinesPrivacyTermsCookies
Mike Johnson
Mike Johnson
May 13, 2026

Is there a formula to predict the next prime number?

Ive been trying to find a pattern in prime numbers.

The primes up to 100: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,972, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 972,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97

I noticed that except for 2 and 3, all primes are of the form 6k±16k \pm 16k±1. But not all numbers of this form are prime (25=6×4+125 = 6 \times 4 + 125=6×4+1).

Is there ANY formula that generates ONLY primes? I heard about:

  • n2+n+41n^2 + n + 41n2+n+41 generates primes for n=0n = 0n=0 to 393939 but fails at n=40n = 40n=40
  • Mersenne primes 2p−12^p - 12p−1
  • Fermats formula 22n+12^{2^n} + 122n+1

Why is finding a prime formula so hard? And are there methods to find the next prime without checking every odd number?

1 answers2.5k views

1 Answer

0
Chen Wei
Chen Wei
May 13, 2026
Accepted
**Short answer:** No polynomial formula can generate only primes (except constant functions). **Proof:** If $f(n)$ is a non-constant polynomial with integer coefficients that generates primes for all integer inputs $n$, then $f(0) = p$ for some prime $p$. Then $f(kp) \equiv f(0) \equiv p \pmod{p}$, so $f(kp)$ is divisible by $p$. Since $f(kp) \to \infty$, eventually $f(kp) > p$, so it would be a larger multiple of $p$ and thus composite. Contradiction. **What about exponential formulas?** The formula $2^{2^n} + 1$ (Fermat numbers) gives primes for $n=0,\ldots,4$ but fails at $n=5$ (composite). Mersenne primes $2^p-1$ are prime for some $p$ but not all. **Whats known:** - There are formulas that generate primes, but theyre either computationally useless or require knowing primes in advance - Millss constant: There exists $\theta > 0$ such that $\lfloor \theta^{3^n} \rfloor$ is always prime — but finding $\theta$ requires knowing primes - The distribution of primes follows $\pi(x) \sim x/\ln x$ but exact prediction is impossible **Why its hard:** Primes are determined by multiplicative structure, but our formulas are built on addition and exponentiation. These two operations interact in complex ways.
Still unsure? Join to comment or ask a follow-up.
Login or Register to post your answer

Suggested questions

Why does 0 factorial equal 1 instead of 0? Simple proof

31.4k

Does 1+2+3+4+... really equal -1/12? Math explained

25.6k

Can someone finally explain the Monty Hall problem?

24.2k

Does the Banach-Steinhaus theorem hold for non-complete normed spaces?

31.1k

Do I need Calculus 3 before learning Fourier series?

3501