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


Groups > comp.lang.python > #8140 > unrolled thread

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

Started byChris Angelico <rosuav@gmail.com>
First post2011-06-22 08:59 +1000
Last post2011-06-22 08:59 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  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 08:59 +1000

#8140 — 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)?

FromChris Angelico <rosuav@gmail.com>
Date2011-06-22 08:59 +1000
SubjectFinding 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)?
Message-ID<mailman.248.1308697176.1164.python-list@python.org>
On Wed, Jun 22, 2011 at 7:48 AM, John Salerno <johnjsal@gmail.com> wrote:
> Thanks for the all the advice everyone. Now I'm on to problem #4, and
> I'm stumped again, but that's what's fun! :)

So now that you've solved it, I'd like to see some fast one-liners to
do the job. (Since Python cares about whitespace, it might not
_technically_ fit on one line, but in the spirit of one-liners, try to
keep it short.)

Here's what I did in Pike, very quickly:
exec 600851475143; for (int i=2;i<ret;++i) while (ret%i==0) ret/=i

Porting it to Python:
ret,i=600851475143,2
while i<ret:
  while not ret%i:
    ret//=i

Bring on your simpler solutions!

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web