링크
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.
python
python - more efficient
A Pythagorean triplet (a,b,c) has gcd(a,b) = gcd(b,c) = gcd(c,d), and is by definition primitive if gcd(a,b,c) = 1
and Pythagorean triplets can be represented as
a = m^2 - n^2, b = 2mn, c = m^2 + n^2
while
m > n > 0
then Pythagorean triplet will be primitive iff exactly one of m, n is even and gcd(m, n)=1
Efficient algorithm use it