[Tutor] improving the speed of prime number code
H.G. le Roy
hgleroy at gmail.com
Fri Feb 6 22:19:36 CET 2009
Hi,
I'm stuck with Problem 10 (
http://projecteuler.net/index.php?section=problems&id=10) :-)
A part of my code deals with the calculation of prime numbers. However it is
really slow. Hopefully you have some ideas how to make it faster.
pz = [2]
# only iterate over odd numbers
for i in xrange(3,2000000,2):
remprod = 1 # product of remainders
for j in xrange(len(pz)):
remprod *= (i % pz[j])
if remprod == 0: # if a number is divisible wo remainder its not prime
break
if remprod > 0:
pz.append(i)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090206/0912c51a/attachment.htm>
More information about the Tutor
mailing list