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:
I noticed that except for 2 and 3, all primes are of the form . But not all numbers of this form are prime ().
Is there ANY formula that generates ONLY primes? I heard about:
- generates primes for to but fails at
- Mersenne primes
- Fermats formula
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 JohnsonMay 13, 2026
so youre telling me theres no pattern to primes?
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
**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