Elementary Number Theory – Formulas for Calculating Pythagorean Triples

elementary-number-theorypythagorean triples

I'm looking for formulas or methods to find pythagorean triples. I only know one formula for calculating a pythagorean triple and that is euclid's which is:

$$\begin{align}
&a = m^2-n^2 \\
&b = 2mn\\
&c = m^2+n^2
\end{align}$$

With numerous parameters.

So are there other formulas/methods?

Best Answer

It doesn't seem cumbersome to me. Just loop on $m$ starting at $2$. Loop on $n$ starting at $1$ or $2$ depending on the parity of $m$ and going up to $m-1$. Check the GCD using Euclid's algorithm. If it is $1$ you have a primitive set, so calculate $a,b,c$. If you want all sets up to some $N$, multiply $a,b,c$ by all values up to $\lfloor \frac Nc \rfloor$. Stop the $m$ loop at $\sqrt N$