24小时热门版块排行榜    

CyRhmU.jpeg
南方科技大学公共卫生及应急管理学院2025级博士研究生招生报考通知
查看: 1745  |  回复: 12
本帖产生 2 个 程序强帖 ,点击这里进行查看
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

微尘、梦想

木虫 (知名作家)

[交流] Project Euler 50 欧拉工程 50 题已有6人参与

素数41能够被写成6个连续素数的和:
                41 = 2 + 3 + 5 + 7 + 11 + 13
这是100以下,能被表示成若干个连续素数相加的素数中项数最多的一个。
1000以下,能被表示成若干个连续素数加和而成的素数中项数最多的一个是953,共有21项。
问:100万以下的素数中,能被若干个连续素数相加得到,并且项数最多的一个是多少?

原题:
引用回帖:
The prime 41, can be written as the sum of six consecutive primes:

41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred.

The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.

Which prime, below one-million, can be written as the sum of the most consecutive primes?

呵呵……闲着没事,我也贴一个,看看大家还有没有热情……

[ Last edited by 微尘、梦想 on 2012-2-17 at 22:28 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

任风云变幻,我笑对人生!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wangww2011

木虫 (著名写手)


小木虫(金币+0.5):给个红包,谢谢回帖
余泽成(金币+2): 鼓励交流! 2012-02-25 04:40:17
引用回帖:
4楼: Originally posted by lurencyj at 2012-02-20 17:26:22:
听说python效率比C++差不多慢个100倍。。。哈哈

这位同学看样子是被严重误导了,且不说有just-in-time这种技术和很多高新能的函数库,就是全用python也没有很慢啊,况且很多时候是可以用优秀算法提高速度的,你当然会说C也可以用同样的算法啊,是的,但是python用起来更简单不是。别忘了,你的时间永远比cpu时间更珍贵。。。
5楼2012-02-20 21:02:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 13 个回答

lijie169

铜虫 (著名写手)


小木虫(金币+0.5):给个红包,谢谢回帖
微尘、梦想(金币+1): 围观奖励,还是等牛人吧,呵呵…… 2012-02-19 07:31:43
楼主也做这个么?我还有好多不会做呢?!想请教下?
2楼2012-02-18 18:13:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wangww2011

木虫 (著名写手)


小木虫(金币+0.5):给个红包,谢谢回帖
微尘、梦想(金币+3, 程序强帖+1): 把算法也贴一下吧,这样大家交流起来也方便,呵呵…… 2012-02-20 07:59:57
貌似以前做过,不过忘了。
继续python中,但是python的官网居然都被墙了是不是?幸好*unix/mac都预装的有python,win7不清楚,xp是肯定没有了,据说win8预装。
结果
CODE:
997651

代码
CODE:
#!/usr/bin/env python

def generate_primes(n):
    isprimes=[True]*n
    for i in range(2,n):
        if isprimes[i]:
            for j in range(2*i,n,i):
                isprimes[j] = False
    primes=[i for i in range(3,n,2) if isprimes[i]]
    primes.insert(0,2)
    return primes


def euler50(num):
    p=generate_primes(num)
    max_n=1
    while sum(p[:max_n])         max_n+=1
   
    for i in range(max_n,2,-1):
        for j in range(len(p)-i):
            tmp=sum(p[j:j+i])
            if tmp>num:break
            if tmp in p:
                return tmp
        
if __name__ == "__main__":
    print euler50(1000000)

[ Last edited by wangww2011 on 2012-2-20 at 03:45 ]
3楼2012-02-20 03:43:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lurencyj

木虫 (著名写手)


小木虫(金币+0.5):给个红包,谢谢回帖
听说python效率比C++差不多慢个100倍。。。哈哈
很女子很弓虽大
4楼2012-02-20 17:26:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通表情 高级回复(可上传附件)
信息提示
请填处理意见