Finding greatest prime factor, was Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

Chris Angelico rosuav at gmail.com
Tue Jun 21 19:02:43 EDT 2011


Oops, realized after posting that there's a bug in my code - it
returns 1 for a perfect square. Need another check in the 'while'
loop, thus:

On Wed, Jun 22, 2011 at 8:59 AM, Chris Angelico <rosuav at gmail.com> wrote:
> exec 600851475143; for (int i=2;i<ret;++i) while (ret%i==0 && ret>i) ret/=i
>
>  while not ret%i and ret>i:

Definitely room for improvement here!

ChrisA



More information about the Python-list mailing list