首页 > 代码库 > 欧拉计划(python) problem 7

欧拉计划(python) problem 7

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 :

import math
sqrt=math.sqrt


def func(x):
    k=int(sqrt(x))+1
    for i in range(2,k):
        if x%i==0:
            return 0
    return 1
k=3
temp=6
while 1:
    temp+=1
    if func(temp)==0:
        continue
    else:
        k+=1
        if k==10001:
            break
print(temp)


result : 104743

timt : 1s


欧拉计划(python) problem 7