[Tutor] OverflowError: cannot fit 'long' into an index-sized integer

Keith Winston keithwins at gmail.com
Tue Jan 7 23:45:49 CET 2014


Hey Danny,

I think you could use the same sqrt(n) on your algorithm to reduce the
search space. I think you could also increment n += 2 to skip even numbers,
the simplest of sieves.

I think the sieve concept is based on the idea that adding is much less
intensive than dividing, so creating the sieve is fairly quick compared to
all those divides. that said, I might put a timer on your algorithm and
compare them!

Oops: I just did it. Yours won, .23s to .34s. What's more, on certain prime
numbers (with large factors), mine breaks. well never mind then. I'm
blaming Jorge.

Dammit: I forgot to include the i += 2 suggestion I made in the above test
(one also has to start i at 3, hopefully obviously). That improves your
time to .11s. Poor Jorge.

Keith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140107/260b3369/attachment.html>


More information about the Tutor mailing list