#A Pythagorean triplet is a set of three natural numbers, a b c, for which, #a2 + b2 = c2 #For example, 32 + 42 = 9 + 16 = 25 = 52. #There exists exactly one Pythagorean triplet for which a + b + c = 1000. #Find the product abc. #answer: 31875000 def pythagorean flag = false for a in (1..1000) for b in (1..1000) c = 1000-a-b if(a**2+b**2 == c**2) puts a, b, c, a*b*c flag = true break end end break if flag end end pythagorean
ProjectRuler-9
最新推荐文章于 2016-12-14 12:10:36 发布