https://projecteuler.net/problem=7

来源:互联网 发布:淘宝网商城婚纱礼服 编辑:程序博客网 时间:2024/05/29 03:03

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 = 200010listprime = [True] * (upper+1)for i in range(2,upper+1):    if listprime[i] == True:        temp = i * 2        while temp < upper:            listprime[temp] = False            temp += icount = 0i = 2while count < 10001 and i < upper:    if listprime[i] == True:        count += 1    i += 1print(i-1)print(count)


 

0 0