Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7283
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.039 |
| X-Spam-Evidence | '*H*': 0.92; '*S*': 0.00; 'instance,': 0.05; 'pm,': 0.10; '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; 'itself;': 0.16; 'rebert': 0.16; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'found,': 0.23; '\xa0if': 0.23; 'code': 0.24; "i'm": 0.27; 'work.': 0.28; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; '24,': 0.29; "won't": 0.30; 'print': 0.31; 'to:addr:python-list': 0.33; 'rather': 0.34; 'chris': 0.34; 'quite': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'fair': 0.37; 'url:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'hope': 0.60; 'stop': 0.62; 'perfect': 0.64; 'square': 0.67; 'prime': 0.73; 'subject:this': 0.76; 'subject:..': 0.82; 'num': 0.84; 'factors': 0.91 |
| 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=dXDPj2hFYiXUjuxESe7R42LMuXx+XOr1HtM0MNw6Z1U=; b=xIaVPAAzJbTbSIOrmvOp6Wi3j+luyyJYzqfP5XSknh9pUU+yviuH3rNLTgj3BI8BXM 91lJdFz7L0ELRtIZfEBTD8gAT8n17DmfMzd0/KeNRgC6T0UuYcL2QYVYpQw09noYTUOr aTBCQdeFBhhPiIbmMygVbNyNf6FtOWgA2ZLbc= |
| 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=NMbGZqLI20TxqH1jjKAGMJk/e3cn9bNhls7xpUSsao6PUNxuuijxttLXny6p5IeuWS 8lsfgd8qpG46+vMc9VMcb8H3oNXsfWCWeMIxzewCNT0a2WNAtKJvpsKkSeSvmTGZ9RPW +helgMUkNiC1sk1sFH8rT4RdFFVigQqN7beug= |
| MIME-Version | 1.0 |
| In-Reply-To | <BANLkTimicVsm7EGMsVu0bXRsa7714MKpwA@mail.gmail.com> |
| References | <BANLkTinWq5pjX2+0OVRvm1Xs7ESmYf0qcw@mail.gmail.com> <BANLkTimicVsm7EGMsVu0bXRsa7714MKpwA@mail.gmail.com> |
| Date | Thu, 9 Jun 2011 19:25:06 +1000 |
| Subject | Re: Any Better logic for this problem.. |
| 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.48.1307611509.11593.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307611509 news.xs4all.nl 49178 [::ffff:82.94.164.166]:39595 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7283 |
Show key headers only | View raw
On Thu, Jun 9, 2011 at 7:06 PM, Chris Rebert <clp2@rebertia.com> wrote: > On Thu, Jun 9, 2011 at 1:31 AM, Ganapathy Subramanium > <sganapathy.subramanium@gmail.com> wrote: >> Hi Guru's, >> I'm working on a solution to find the prime factor of the number >> This part of the code works.. http://www.pastie.org/2041584 > > For the archives, that code is: > > for items in prime_numbers: > if num % items == 0: > prime_factors.append(items) > > print 'The prime factors are : ' , prime_factors Prime factors don't quite work that way. The prime factors of 24, for instance, are 2, 2, 2, and 3. But if you're looking for _unique_ prime factors, then this will work. Rather than find all prime numbers up to num, stop at sqrt(num) - it's not possible to have any prime factors larger than that. (Be sure to include the square root itself; range(2,sqrt(num)) won't work if num is a perfect square. Use range(2,sqrt(num)+1) for safety.) That will save a fair amount of effort. Also, if you divide num by each factor found, it'll make the numbers smaller, which may be faster. Hope that helps! Chris Angelico
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Any Better logic for this problem.. Chris Angelico <rosuav@gmail.com> - 2011-06-09 19:25 +1000
Re: Any Better logic for this problem.. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-10 10:39 +1200
Re: Any Better logic for this problem.. Chris Angelico <rosuav@gmail.com> - 2011-06-10 08:44 +1000
csiph-web