首页 > 编程语言 > 详细

欧拉计划(python) problem 7

时间:2015-01-26 22:45:30      阅读:303      评论:0      收藏:0      [点我收藏+]

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

原文:http://blog.csdn.net/zhangzhengyi03539/article/details/43163713

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!