码迷,mamicode.com
首页 > 其他好文 > 详细

Summation of primes

时间:2014-05-09 16:20:08      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   color   

是我算法不对,还是笔记本CPU太差?

我优化了两次,还是花了三四个小时来得到结果。

在输出上加1就是最终结果。

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

bubuko.com,布布扣
def isprime(n):
    boolisprime = True
    for i in xrange(3,n):
        if n % i == 0:
            boolisprime = False
            break
    return boolisprime

def primenumber(n):
    i = 1
    sumprime = 0
    while True:
        if isprime(i) == True:
            sumprime += i
            print i,sumprime
        if i > n:
            break
        i += 2
    return sumprime
print primenumber(2000000)+1
bubuko.com,布布扣

 

bubuko.com,布布扣

Summation of primes,布布扣,bubuko.com

Summation of primes

标签:style   blog   class   code   java   color   

原文地址:http://www.cnblogs.com/aguncn/p/3718137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!