In [2]:
from math import gcd
for m in range(2, 23, 2):
for n in range(1 + (m % 2), m, 2):
if gcd(m,n) == 1:
a = (m + n) * (m - n)
b = 2 * m * n
c = m * m + n * n
p = a + b + c
if (1000 % p) == 0:
k = 1000 // p
print((k*a, k*b, k*c))
print(k**3 * a * b * c)
Explanation: A Pythagorean triplet is said to be primitive if the three numbers have no common factor. Every Pythagorean triplet is a multiple of a primitive triplet.
If $m > n$ then $(m^2 - n^2, 2mn, m^2 + n^2)$ is a Pythagorean triple. The triple is primitive if and only if $m-n$ is odd and $\gcd(m, n) = 1$. Furthermore, every primitive Pythagorean triple can be generated in this manner.
Our strategy is to find all primitive Pythagorean triplets whose sums are factors of 1000, and scale them so their sums are equal to 1000.