# How to find all Pythagorean triples containing a given number?

I am solving one question related to right triangle in which one side is $12$ and I have to find the greatest possible perimeter of such a triangle.

Is there any way to find all Pythagorean triples if only one side is given?

Let a Pythagorean triple be of the form $(x,y,z)$ where one of $x, y$ or $z$ is 12. From Elementary Number Theory we know that $z$ is odd, and $x \not\equiv y \pmod{2}$ (i.e. one of $x$ and $y$ is odd and one is even). (I will omit the proof of this but it is fairly simple). We also know that for primitive Pythagorean triples: $$x=2pq, \\ y=p^2-q^2 \\ z=p^2+q^2\\$$ for some $p>q>0$.

We therefore know that 12 must be $x$ as $x$ is even, so we look at all the factors of $6$ to find the possible values for $p,q$.

$$6 = 6 \cdot 1=2 \cdot 3$$

So our possible values for $p$ are: $p=6$ or $p=3$, and our possible values for $q$ are: $q=1$ and $q=2$.

With $p=6,q=1$ we get: $x=12,y=35,z=37$ and $P=x+y+z=84$.

With $p=3,q=2$ we get: $x=12,y=5,z=13$ and $P=30$.

So the maximal perimeter corresponds to the triangle with sides $12, 35, 37$ and perimeter $84$.

---EDIT---

The above only considered primitive Pythagorean triples. To consider all P.ts we must look at those where all numbers are less than 12 and find the non primitive triples which arise from them. These are:

$$(4,3,5) \rightarrow (12,9,15),(16,12,20)$$ Upon multiplying by $3$ and $4$ respectively.

Neither of these triples give rise to a perimeter greater than $84$, so the triangle with one side of length $12$ with greatest perimeter is the triangle corresponding to $(12,35,37)$

• You reversed the roles of $y$ and $z$. You meant $y = p^2 \color{red}{-} q^2$ and $z = p^2 \color{red}{+} q^2$. The formula you are citing is for primitive Pythagorean triples, that is, those that are relatively prime. Commented Dec 27, 2015 at 18:00
• Sorry, yes you are correct in both cases. I will edit the part relative to your first point now. WRT your second point, could one not look at all primitive Pythagorean triples where all sides are less than 12, and find the non primitive triples with one side 12 that arise from these? Commented Dec 27, 2015 at 18:05

Hint: There are no integer right triangles with a hypotenuse of 12 (why?), so the side of length $12$ must be a leg, and then $144 = c^2-b^2 = (c+b)(c-b)$.

• why? (for first line) Commented Dec 27, 2015 at 15:37
• @Ayushakj If it were, you could express $144$ as a sum of two nonzero squares. Can you? Commented Dec 27, 2015 at 15:38
• I think the OP is asking for a right triangle with one side 12, You're answering about a hypotenuse of 12. Commented Dec 27, 2015 at 15:40
• @EthanBolker I clarified the answer; I was talking about a leg of 12. Commented Dec 27, 2015 at 15:42
• So now I have to substitute value of c and b. or any other way. Commented Dec 27, 2015 at 15:43

If we solve any of Euclid's formula functions for $$n$$, we can find triples for any given side, if they exist, with a finite search of $$m$$ values.

For $$A=m^2-n^2$$, we let $$n=\sqrt{m^2-A}$$ where $$\lceil\sqrt{A+1}\space\rceil\le m\le \bigl\lceil\frac{A}{2}\bigr\rceil$$. If any $$m$$ yields a positive integer $$n$$, we have $$(m,n)$$ for a Pythagorean triple.

For example, if $$A=27$$, then $$5\le m \le 14$$ and we find $$(m,n)=(6,3)$$ and $$(14,13)$$; we find $$f(6,3)=(27,36,45)$$ and $$f(14,13)=(27,364,365)$$. If $$A=12$$, we find only $$f(4,2)=(12,16,20)$$ which is $$4*(3,4,5)$$.

For $$B=2mn$$, $$n=\frac{B}{2m}$$ where $$\lceil\sqrt{2B}\space\space\rceil\le m \le \frac{B}{2}$$; for $$B=12,\space\space3\le m\le 6$$ and we find only $$f(6,1)=(35,12,37).$$

For $$C= m^2+n^2,\space n=\sqrt{C-m^2}$$ where $$\biggl\lceil\sqrt{\frac{C}{2}}\space\space\biggr\rceil \le m\le\bigl\lfloor\sqrt{C}\bigr\rfloor$$. For example, if $$C=1105,\space 24\le m \le 33$$ and we find four triples that match. $$f(24,23)=(47,1104,1105)\quad f(31,12)=(817,744,1105)\quad f(32,9)=(943,576,1105)\quad f(33,4)=(1073,264,1105)$$