Problem 9
Problem 9
# Problem_9.py """ A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, pow(a, 2) + pow(b, 2) = pow(c, 2) For example, pow(3, 2) + pow(4, 2) = 9 + 16 = 25 = pow(5, 2). There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. 找出满足a + b + c = 1000的毕达哥拉斯三元数组(Pythagorean triplet) 找出三数之积 """ import math ans = [] for a in range(1, 1000): for b in range(a, 1000): power = pow(a, 2) + pow(b, 2) c = math.sqrt(power) if c % int(c) != 0.0: continue c = int(c) print(a, b, c, a+b+c) if a+b+c == 1000: ans.extend([a, b, c]) break print(ans) tot = 1 for i in ans: tot *= i print(tot)
Resistance is Futile!