24小时热门版块排行榜    

查看: 3536  |  回复: 23
本帖产生 7 个 程序强帖 ,点击这里进行查看
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

[交流] Euler Project Q12 欧拉工程第十二题 已有9人参与

Question 12:
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

     1: 1
     3: 1,3
     6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

翻译:

自然数求和可生成三角数列.第七个三角数是1 + 2 + 3 + 4 + 5 + 6 + 7 = 28.前10个三角数列元素是:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

下面列出前7个三角数及其整除数:
     1: 1
     3: 1,3
     6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28
可以看出,28是第一个有超过5个整除数的三角数.

那么,第一个有超过500个整除数的三角数是多少?

[ Last edited by libralibra on 2011-5-17 at 05:41 ]
回复此楼

» 猜你喜欢

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

matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

holmescn

金虫 (正式写手)

★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖
余泽成(金币+3, 程序强帖+1): 鼓励参与交流! 2011-05-19 19:16:20
CODE:
# -*- coding: utf-8 -*-

# 初始化一个质数表
i = 0
primes = range(2, 100)
while i < len(primes):
    primes = [x for x in primes if x == primes[i] or x % primes[i] != 0]
    i = i + 1

def numbersOfFactors(n):
    """计算n的因子数
    使用了sudo说的计算方法
    加上一个质数分解
    """
    factorNumbers = 1
    factorTimes = 0
    i = 0
    while i < len(primes):
        if n % primes[i] == 0:
            factorTimes += 1
            n /= primes[i]
            continue
        else:
            if factorTimes != 0:
                factorNumbers *= factorTimes + 1
                factorTimes = 0
            i = i + 1
            if n == 1:
                break
    return factorNumbers

# 从第三个三角数开始算,只算第奇数个三角数
n = 3
while numbersOfFactors(n*(n+1)/2) < 500:
    n += 2

# 为防止对偶数个三角数的遗漏,有最后这个计算
if numbersOfFactors(n*(n-1)/2) > 500:
    print n*(n-1)/2
else:
    print n*(n+1)/2

写了个质数分解版的。速度是很快啊!

[ Last edited by holmescn on 2011-5-19 at 16:34 ]
16楼2011-05-18 17:52:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

holmescn

金虫 (正式写手)


小木虫(金币+0.5):给个红包,谢谢回帖
引用回帖:
Originally posted by fan6cy at 2011-05-24 09:00:01:
首先列出matlab计算的结果和时间:
y =

    76576500


time =

    4.5780
如果你觉得我的程序还不错,请继续往下看:
本程序一共有三个程序组成,fibon.m,nfactor.m,ruler12.m
fibon.m
function y ...

推荐使用BBCode重新编辑你的代码,让代码更好看,更易读。
20楼2011-05-24 09:51:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 libralibra 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见