# Meta-Pythagorean Triple

How can I find all Pythagorean triples $(a,b,c)$ such that the hypotenuse $c$ is a leg in another Pythagorean triple?

For example, $(3,4,5)$ is such a Pythagorean triple because the length of the hypotenuse for this right triangle is 5 and this length shows up as a leg in another Pythagorean triple $(5,12,13)$.

This is a lot easier than it looks like. It turns out that the answer is "all of them". Actually, every single number $n$ greater than $2$ appears as the leg of some pythagorean triangle. If $n$ is not a power of two, the following way works: First, assume $n$ is odd. Then $$\left( n,\frac{n^2 - 1}{2}, \frac{n^2 + 1}{2}\right)\quad \text{or} \quad \left(\frac{n^2 - 1}{2}, n, \frac{n^2 + 1}{2}\right)$$ is a Pythagorean triple. If $n$ is even, say $n = 2^km$ with $m\geq 3$ odd, then use the above on $m$, and scale the pythagorean triple you get by $2^k$.

If $n > 2$ is a power of $2$, use $(3, 4, 5)$ with appropriate scaling.

• @Jack Lam Your question is old but I think I have an answer that will help with your search for a triple with a side matching a given hypotenuse. My functions get downvoted because they are not the standard formula for generating Pythagorean triples but they are the result of a decade of original research and they have the advantage of letting one find matching sides easily. Apr 29, 2019 at 17:21
• Moreover, if $n>2$ and $n\ne 2\mod 4$, $n$ is a leg of a primitive Pythagorean triangle. If $n$ is odd, the above answer provides one. If $4\mid n$, let $m$ be $n$'s largest odd factor, as above; then let $t=m$ and $u=n/2m$. Then $(2tu=n, |t^2-u^2|, t^2+u^2)$ is a primitive Pythagorean triangle. Jan 3 at 16:22

There is a primitive Pythagorean triple with side $$A$$ equal to any odd number $$\ge3$$. We can find those primitives (or the double or perfect square multiples of them) by solving the $$A$$ or $$B$$ functions for $$n$$ and doing a finite search of $$m$$ values (based on $$C$$ values in this problem). For $$A=m^2-n^2$$, we let $$n=\sqrt{m^2-A}\implies n=\sqrt{m^2-C}$$ and the search will be limited to values of $$m$$ where

$$\lceil\sqrt{C+1}\space\rceil\le m\le \biggl\lceil\frac{C}{2}\biggr\rceil$$ For any $$m$$ that yields positive integer $$n$$, we have $$(m,n)$$ for a Pythagorean triple.

For example, we want to find matches for the hypotenuse of $$27,36,45$$. $$\text{Our limits are }\lceil\sqrt{45+1}\space\rceil=7\le m\le \biggl\lceil\frac{45}{2}\biggr\rceil=23$$

For most values of $$m$$, we find $$n\notin\mathbb{N}$$ but we do find three matches. $$f(7,2)=(45,28,53)$$ $$f(9,6)=(45,108,117)$$ $$f(23,22)=(45,1012,1013)$$

For $$765$$ and $$1305$$, there are $$6$$ matches each and it appears that the chances of having matches increases with the magnitude of $$C$$.

Now let's take the triple $$(14,48,50)$$ where $$C$$ is even.

$$\text{For }B=2mn\quad n=\frac{B}{2m}\text{ where } \lceil\sqrt{B}\space\space\rceil\le m \le \frac{B}{2}$$

$$\text{for }B=C=50\quad \quad \lceil\sqrt{50}\space\space\rceil=8\le m \le \frac{50}{2}=25$$

$$\text{We find only }n=\frac{50}{2*25}=1\quad \quad f(25,1)=(624,50,626)$$

All pythagorean triples on the integers have the following form:

$$a=2xy$$

$$b=x^2-y^2$$

$$c=x^2+y^2$$

Note every even number can be an $$a$$.

Any integer can be a $$c$$ unless the highest power of some prime, p, in its prime factorization is congruent to 3(mod 4) and is raised to an odd power.

A any $$b$$ will work. For odd b let $$x=(b+1)/2)$$ and $$y=(b-1)/2$$. For even $$b$$, let $$b=2k$$. The let $$x=k+1$$ and $$y=k-1$$.

Using these rules you can find numbers that belong to both groups.

• The following formula generates the subset of Pythagorean triples where $GCD(A,B.C)$ is an odd square. This includes, no trivials, all primitives and only about $1/3$ the non-primitives like $(27,36,45)$ that Euclid’s formula produces. Note: conventionally, A is always odd for primitives. \begin{align*} A=(2n-1)^2+ & 2(2n-1)k \\ B= \qquad\quad\quad & 2(2n-1)k+ 2k^2\\ C=(2n-1)^2+ & 2(2n-1)k+ 2k^2\\ \end{align*} It is the same as though $A=(2n-1+k)^2-k^2\quad B=2(2n-1+k)k\quad C=(2n-1+k)^2+k^2$ Aug 8, 2021 at 2:52