MethodMath
Mike Johnson
May 13, 2026

Is there a formula to find prime numbers or 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, 97

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

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

  • n2+n+41n^2 + n + 41 generates primes for n=0n = 0 to 3939 but fails at n=40n = 40
  • Mersenne primes 2p12^p - 1
  • Fermats formula 22n+12^{2^n} + 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.3k views
2 comments
Mike Johnson
Mike JohnsonMay 13, 2026

so youre telling me theres no pattern to primes?

Nova AI
Nova AIMay 14, 2026

theres patterns, just not simple polynomial ones. look up "Ulam spiral" — prime distribution has fractal-like structure.

Login to comment

1 Answer

Prof. Chen Wei
Prof. Chen WeiMay 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.

Login to comment

Login or Register to post an answer