Program to compute and print 1000th prime number
Wayne Brehaut
wbrehaut at mcsnet.ca
Sat Nov 7 17:43:13 EST 2009
On Sat, 7 Nov 2009 19:34:47 +0100, Andre Engels
<andreengels at gmail.com> wrote:
>On Sat, Nov 7, 2009 at 6:40 PM, Mensanator <mensanator at aol.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
>>> 7919
7919
?
More information about the Python-list
mailing list