How can I find all primitive pythagorean multiples given one even number including that number?

162 Views Asked by At

I am trying to make an algorithm to find all pythagorean triples given a even number such as 4. Then the triple would be (3,4,5). Is there a way to do this? I am using maple to do this but can also work with python.

My code so far is PythagoreanTriplets := proc (x) local y, z, a, b, primitive; x; 2*ab; y = a^2-b^2; z = a^2-b^2; primitive := sqrt(x^2+y^2); for a in divisors(x) do for b in divisors(x) and not a do if gcd(a, b) = 1 then primitive := print(x, y, z) end if end do end do; return primitive end proc

1

There are 1 best solutions below

0
On

Example.

Given an even number, say $40$, then $pq = 20$ and, if you are looking for only primitive Pythagorean triples, then $p \not \equiv q \pmod 2$. That leaves the following possibilities.

\begin{array}{c} p & q & p^2-q^2 & p^2+q^2 & \text{triple}\\ 20 & 1 & 399 & 401 & (40, 399, 401)\\ 10 & 2 \\ 5 & 4 & 9 & 41 & (9, 40, 41) \end{array}