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

全部博文(47)

文章存档

2008年(47)

我的朋友

分类:

2008-11-15 19:21:38

Problem 44

23 May 2003

Pentagonal numbers are generated by the formula, Pn=n(3n1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk Pj| is minimised; what is the value of D?

我们令 Pj+Pk=Pm, jm只能有一种分解即不会出现Pj’+Pk’=Pm,其中Pj’!=Pj, Pk'!=Pk, 我们遍历符合条件的Pm, 将起分解后,判断是否Pk-Pj是pentagonal数    

def fun44():
    #n(3n-1)/2
    #pj+pk=pm j
    m = 3
    while 1:
        pm = m*(3*m-1)/2
        for k in range(m-1, 0, -1):
            pk = k*(3*k-1)/2
            pj = pm - pk
            if pj >= pk:
                m += 1
                break
            else:
                t = int((2*pj/3)**0.5)
                if (t+1)*(3*t+2) == 2*pj:
                    pn = pk - pj
                    t = int((2*pn/3)**0.5)
                    if (t+1)*(3*t+2) == 2*pn:
                        return pk, pj, pm, pn, pk-pj
        m += 1

answer is 5482660, pk=7042750, pj=1560090, pm=8602840, pn=5482660
time:1.68700003624
阅读(549) | 评论(0) | 转发(0) |
0

上一篇:Problem 43

下一篇:Problem 46

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