Skip to content

Instantly share code, notes, and snippets.

@alanduan
Created July 19, 2012 02:43
Show Gist options
  • Save alanduan/3140417 to your computer and use it in GitHub Desktop.
Save alanduan/3140417 to your computer and use it in GitHub Desktop.
get the nth prime number.
import math
def prime(n):
p = [2]
x = 3
while len(p) < n:
isprime = True
for i in p:
if i > math.sqrt(x):
break
if x % i == 0:
isprime = False
break
if isprime:
p.append(x)
x += 2
return p[-1]
import time
s = time.time()
print prime(100000)
print time.time() - s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment