EularProject 7:計算10001素数


10001st prime
Problem 7
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?
python code :
<span style="font-family:Times New Roman;font-size:18px;">import math
sqrt=math.sqrt


def func(x):
    k=int(sqrt(x))+1
    for i in range(2,k):
        if x%i==0:
            return False
    return True
k=3
temp=6
while 1:
    temp+=1
    if func(temp):
        k+=1
        if k==10001:
            break
print(temp)</span>

result : 104743
timt : 1s
------------------
ご健康を祈ります
華電北風が吹く
天津大学コンピュータ科学と技術学院
天津市衛津路92号
郵便番号:30072
メールアドレス:[email protected]