Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86651
  • 博文数量: 47
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-11 12:11
文章分类

全部博文(47)

文章存档

2008年(47)

我的朋友

分类:

2008-11-12 13:00:27

Problem 10

08 February 2002

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

Find the sum of all the primes below two million.


def fun10():
    primes = [2]
    result = 2
    i      = 3
    while i < 2000000:
        s = math.sqrt(i)
        for p in primes:
            if p > s:
                primes.append(i)
                result += i
                break
            else:
                if i%p == 0:
                    break
        i += 2
    return result

answer is 142913828922, 一共用时12.3910000324,太长了
阅读(280) | 评论(0) | 转发(0) |
0

上一篇:Problem 9

下一篇:Problem 14

给主人留下些什么吧!~~