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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'bug': 0.02; 'wed,': 0.03; 'exec': 0.07; '(int': 0.09; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'angelico': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject: \n ': 0.16; '\xa0while': 0.16; 'subject:was': 0.16; 'header:In-Reply-To:1': 0.21; 'posting': 0.21; 'loop,': 0.23; 'code': 0.24; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'subject:How': 0.30; 'to:addr:python- list': 0.33; 'chris': 0.34; 'received:google.com': 0.37; 'received:209.85': 0.37; 'another': 0.37; 'subject:can': 0.38; 'subject:: ': 0.38; 'room': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'subject:, ': 0.60; 'perfect': 0.64; 'subject:. ': 0.65; 'realized': 0.73; "'while'": 0.84; 'subject:over': 0.84; 'here!': 0.91; 'subject:much': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=+wH39Xsx2Vy+W+KxEfFclXTICPTp8rJGg+/uqPydl5c=; b=ZauTvNfim5g9Y0MHLY2epZ+zxGbEe+v1KDiAF3pCr2SZ/p2LuccEs/n3AMDF9+Q5lC 7a1e8MPib2E3XdemW3qhp5i7AGOtQAGEsAXS5EhvyYK7EopGBJCmnpjIFJuHMNye0dWn tkGNtVr9ZfryqMOPH+w3dO+FGQ3/6/j1NsoJA=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=uNoA3qhSKzy5rYavWdq1uMo7zGDnz7JgUV4rHUU9KIM67EqbQK8WIUq0bvgpYc1TwU sy5k01ynEL9NdC4aSuo/hYslLnJjOHo/QTLX/PcAgXJhiPsphFEYhVCbZT9xHVEGazkM 0JyHNSOoTTnzl9hgti8+K90MmCi2mg0EH+AMk=
MIME-Version 1.0
In-Reply-To <BANLkTim+Z=oouj1Z1kBr2qXYE2mbd55wKg@mail.gmail.com>
References <BANLkTim+Z=oouj1Z1kBr2qXYE2mbd55wKg@mail.gmail.com>
Date Wed, 22 Jun 2011 09:02:43 +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>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.250.1308697366.1164.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 82.94.164.166
X-Trace 1308697366 news.xs4all.nl 49181 [::ffff:82.94.164.166]:45635
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8142

Show key headers only | 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