# How to find prime numbers

I am looking for a formula that tells me what the next prime number will be. It is hard to do this without a formula because for example there is a small gap between 17 and 19 then a big one between 23 and 29 so it is sometimes hard to find the next one quickly.

• There is no formula for the next prime number - they behave randomly, at least at the small scale. However, we do know something about how they are distributed (you mentioned the "gap" between successive primes) see here en.wikipedia.org/wiki/Prime_number_theorem or see here en.wikipedia.org/wiki/Prime_number#Formulas_for_primes May 10 '13 at 12:27
• What is it with prime numbers and formulas today? What you ask is impossible. All you can do is search. May 10 '13 at 12:27
• This is a similar question: math.stackexchange.com/questions/164767/… May 10 '13 at 12:27
• I don't think such a formula (short than factor all numbers...) exists.
– mau
May 10 '13 at 12:27
• You might want to try this Mathematica command in Wolfram Alpha: Table[(Exp[MangoldtLambda[n]]^(-MoebiusMu[n]) - 1)/(n - 1)*n, {n, 2, 32}] which outputs: {2, 3, 0, 5, 0, 7, 0, 0, 0, 11, 0, 13, 0, 0, 0, 17, 0, 19, 0, 0, 0, 23, 0, 0, 0, 0, 0, 29, 0, 31, 0} May 10 '13 at 12:35

## 1 Answer

I just invented this last week Copy the following into Mathematica, select all, right-click on Convert To, choose StandardForm.

N[Sum[2/10^((n*(Floor[c/n] + 1) - c)s), {n, 1, Floor[Sqrt[ c]]}] + Sum[ 2/(10^((n(Floor[c/n] + 1) - c)s) (10^(ns) - 1)), {n, 1, Floor[Sqrt[ c]]}] + Sum[2/(10^((o^2 - o - c) s)(10^(os) - 1)), {o, Floor[Sqrt[c]] + 1, max}], ((max + 1)^2 - c)*s]; AbsoluteTiming[Flatten[ Position[Partition[ RealDigits[%][[1]], s, s, -1], {(0) .., 2}]]] + c

-end

c=crossover s=spacing

The crossover is the number which you want to surpass. The spacing is difficult to determine, so I'll say that in general, if you use a number which is equal to the number of digits of the max^2, you should be safe. So for all primes up to 100^2 = 10000, that is five digits, so use a 5 for the spacing. Follow this rule and you should be safe.