Problem 44
Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:
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 are pentagonal and D = |Pk − Pj| is minimised; what is the value of D?
五边形数由公式Pn=n(3n−1)/2生成。前十个五边形数是:
可以看出P4 + P7 = 22 + 70 = 92 = P8。然而,它们的差70 − 22 = 48并不是五边形数。
在所有和差均为五边形数的五边形数对Pj和Pk中,找出使D = |Pk − Pj|最小的一对;此时D的值是多少?
pentagon = {n*(3*n-1)/2 for n in range(1,10000)}
for pi in pentagon:
for pk in pentagon:
if pk < pi:
if pi - pk in pentagon and pi + pk in pentagon:
print([pi-pk])