My backwards logic

Dave Angel davea at davea.name
Fri Sep 5 23:10:40 EDT 2014


Seymore4Head <Seymore4Head at Hotmail.invalid> Wrote in message:
> On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head
> <Seymore4Head at Hotmail.invalid> wrote:
> 

> 
> If you start with the list [3,5,7] and step through the list of all
> remaining odd numbers (step 2), and start appending numbers that won't
> divide by numbers already appended in the list, that would seem like a
> pretty efficient way to find all prime numbers.
> 
> 

Yes, that's a well known optimization.  In addition,  you can stop
 once you reach the square root of the target.  No point in
 dividing by the higher numbers in the list,  since if the result
 comes out even, you'd have already exited the loop.


-- 
DaveA




More information about the Python-list mailing list