A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
$$a^2 + b^2 = c^2$$ For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product $$abc$$.
A problem of 'Linear indeterminate equation', a.k.a. 'Diophantine equation'.
Refer to Diophantine equation
We have equation:
from math import ceil
def solve(sum_of_three):
# solve determinate equation for `b` and `c`
def solve_b_c(a):
_1, _2 = sum_of_three - a, pow(a, 2) // (sum_of_three - a)
return (_1 - _2) // 2, (_1 + _2) // 2
a_upper_bound = ceil(sum_of_three / 3)
for a in range(1, a_upper_bound):
b, c = solve_b_c(a)
if pow(a, 2) + pow(b, 2) == pow(c, 2):
return (a, b, c), a * b * c
solve(12)
solve(1000)