Quickest procedure needed

Jonathan Sondow jsondow at alumni.princeton.edu
Mon Jan 15 19:43:13 CET 2007


A couple of optimisations spring to mind...

1) Rather than checking whether the quotient is greater than 1, check  
whether Prime[n + 1] - Prime[n] > Log[Prime[n]].  This will eliminate a  
costly division.

2) The integer part of Log[Prime[n]], which is all that you need, changes  
very infrequently for large n.  For example, e^12 = 162754.791... and e^13  
= 442413.392... .  So for all N such that 162754 <= Prime[n] <= 442413,  
you can replace Log[Prime[n]] with the constant 12.  Much more efficient!

Putting these two steps together, for 14913 <= n <= 37128, you can simply  
check for Prime[n + 1] - Prime[n] > 12.

Nick


On Mon, 15 Jan 2007 18:01:43 -0000, Artur <grafix at csl.pl> wrote:

>
> I would like to ask more advanced in Mathematica seqfans about improove  
> procedure to do much quikest (my is extremaly slowly)
> a = {}; Do[d = (Prime[n + 1] - Prime[n])/Log[Prime[n]] // N; If[d > 1,  
> AppendTo[a,Prime[n]]], {n, 1, 2263}]; a
>
> ARTUR
>
>







More information about the SeqFan mailing list