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.
-
1There 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 http://en.wikipedia.org/wiki/Prime_number_theorem or see here http://en.wikipedia.org/wiki/Prime_number#Formulas_for_primes – rondo9 May 10 '13 at 12:27
-
1What is it with prime numbers and formulas today? What you ask is impossible. All you can do is search. – Harald Hanche-Olsen May 10 '13 at 12:27
-
This is a similar question: http://math.stackexchange.com/questions/164767/prime-number-generator-how-to-make – Mats Granvik 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
-
There are actually formulas, but they are all equivalent to some searching algorithm. – Jean-Claude Arbaut May 10 '13 at 12:29
-
1You 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} – Mats Granvik May 10 '13 at 12:35
-
Use the sieve of Eratosthenes – Riccardo.Alestra May 10 '13 at 12:37
-
http://math.stackexchange.com/questions/386288/how-to-calculate-prime-numbers – JRN May 10 '13 at 13:07
-
For formulas (bad approach, but funny), have a look at this and that. @rondo9, there is a formula for next prime number, but probably not what you would expect. – Jean-Claude Arbaut May 11 '13 at 10:26
1 Answers
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.
- 27