Edward Elliott wrote:
[in reponse to some prime-number code]
> 5. you can do better than checking every odd number (next+2) to find the
> next prime, but I'm too tired to look into it right now.  it may require
> more complex machinery.

You only need to check the prime numbers up to sqrt(n).  If you're
calculating primes in sequential order, this is easy.  Otherwise, you
can remove a third of the odd divisors by considering only odd numbers
of the form 6k±1 (because 6k±3 is divisible by 3).

def potential_primes():
   yield 2
   yield 3
   i = 6
   while True:
      yield i - 1
      yield i + 1
      i += 6

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to