ITeye博客

No.7 The 10001st prime number

诗意的栖居 · 2012-08-23 16:16 · 算法 · 编程语言 · Markdown

Q: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

A: import math import time

t1 = time.time()

def getNum(n): #for i in range(2,int(n/2)): for i in range(2,int(math.sqrt(n))+1): if n % i == 0: return 0 return n

count = 2 i = 5

while count < 100001: if getNum(i): count += 1 i += 2

print "The 10001st prime number is %d" %(i - 2)

t2 = time.time() print "time used: %s" %(t2 - t1)

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。