Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8142

Re: 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)?

References <BANLkTim+Z=oouj1Z1kBr2qXYE2mbd55wKg@mail.gmail.com>
Date 2011-06-22 09:02 +1000
Subject Re: 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)?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.250.1308697366.1164.python-list@python.org> (permalink)

Show all headers | View raw


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@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: 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@gmail.com> - 2011-06-22 09:02 +1000

csiph-web