2014年9月22日月曜日

140922

Project Euler


Problem 44

Pn = n (3n - 1) / 2

副産物を記しておく。

def p(m)
  (3 * m ** 2 - m) / 2
end

puts p(91650) + p(52430) == p(105586) # false

puts p(91650) + p(52430) == p(105587)
puts p(91650) - p(52430) == p(75172)

puts p(110461) + p(95506) == p(146024)
puts p(110461) - p(95506) == p(55500)

puts p(121168) + p(111972) == p(164983)
puts p(121168) - p(111972) == p(46303)

puts p(129198) + p(73745) == p(148763)
puts p(129198) - p(73745) == p(106084)

出力結果
false
true
true
true
true
true
true
true
true