您的位置:首页 > 理论基础 > 计算机网络

https://projecteuler.net/problem=7

2016-02-24 20:33 627 查看

10001st prime


Problem 7

Published
on Friday, 28th December 2001, 06:00 pm; Solved by 257306; Difficulty rating: 5%

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?

 

本来想用最笨的方法,从小到大一个一个算,后来看到素筛法,就随便写了些,还是感觉,如果数量再大,这个方法也不好用

upper = 200010
listprime = [True] * (upper+1)
for i in range(2,upper+1):
if listprime[i] == True:
temp = i * 2
while temp < upper:
listprime[temp] = False
temp += i
count = 0
i = 2
while count < 10001 and i < upper:
if listprime[i] == True:
count += 1
i += 1

print(i-1)
print(count)


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: