ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Program to compute and print 1000th prime number
by Andre Engels other posts by this author
Nov 7 2009 10:39AM messages near this date
Re: Program to compute and print 1000th prime number | Re: Program to compute and print 1000th prime number
On Sat, Nov 7, 2009 at 6:40 PM, Mensanator <mensanator@[...].com>  wrote:

> > Tongue in cheek solution:
> >
> > import urllib2
> >
> > url = 'http://primes.utm.edu/lists/small/10000.txt'
> > primes = []
> > for line in urllib2.urlopen(url).read().splitlines():
> >     values = line.split()
> >     if len(values) == 10:
> >         primes.extend(values)
> > print primes[1000-1]
> 
>  Nice, but you can do better.
> 
> >>> import gmpy
> >>> n = 1
> >>> for i in xrange(1000):
>         n = gmpy.next_prime(n)
> >>> print n
>  7919

With the help of the solutions given so far, I can do even better than that:

n = 7919
print n


-- 
André Engels, andreengels@[...].com
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Ray Holt
Xavier Ho
Wayne Brehaut
John Posner
Mensanator
Andre Engels
ssteinerX@gmail.com
Raymond Hettinger
Robert P. J. Day
Robert P. J. Day

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved