[Tutor] OverflowError: cannot fit 'long' into an index-sized integer
Keith Winston
keithwins at gmail.com
Wed Jan 8 00:15:06 CET 2014
On Tue, Jan 7, 2014 at 5:45 PM, Keith Winston <keithwins at gmail.com> wrote:
> 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
>
>
--
Keith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140107/49a5f68a/attachment.html>
More information about the Tutor
mailing list