I know how to generate regular Pythagorean Triples given two positive integers P and Q such that $$a=2*p*q$$ $$b=p^2-q^2$$ $$c=p^2+q^2$$ where $p>q$, but I want to find scenarios where $a$ and $b$ can also be written in the format $p^2+q^2$. Specifically, I am looking for a generalized way of finding all situations where the hypotenuses of the first two triples form the legs of the third triple. $$$$ I want to be able to generate a formula for finding these special triples.

So far, I have been able to find four cases where this holds true by using the brute force method.

$P_1$ $Q_1$ $A_1=2P_1Q_1$ $B_1=P_1^2-Q_1^2$ $C_1=A_3$
10 2 40 96 104
16 4 128 240 272
15 9 270 144 306
21 3 126 432 450
$P_2$ $Q_2$ $A_2=2P_2Q_2$ $B_2=P_2^2-Q_2^2$ $C_2=B_3$
12 3 72 135 153
12 9 216 63 225
12 8 192 80 208
20 12 480 256 544
$P_3$ $Q_3$ $A_3=2P_3Q_3=C_1$ $B_3=P_3^2-Q_3^2=C_2$ $C_3=C_1^2+C_2^2$
13 4 104 153 185
17 8 272 225 353
17 9 306 208 370
25 9 450 544 706

As you can see, the third chart shows Pythagorean triples with legs that are also hypotenuses of the previous charts. For example, the right triangle with sides (104, 153,185) corresponds to the right triangles with (40,96,104) and (72,135,153). The P and Q vales show $P_1^2+Q_1^2=2P_3Q_3$ ($10^2+2^2=2*13*4=104$), and $P_2^2+Q_2^2=P_3^2-Q_3^2$ ($12^2+3^2=13^2-4^2=153$).

I gathered this information using the highly inefficient and laborious method of inputting a table of P and Q values into Google sheets up to P and Q being less than or equal to 25. Then, I searched the data by using vlookup and countif functions, after sorting it a bit.

$$$$ I think there must be a way of simplifying this process, but it eludes me. How can I (in a much less time consuming way) generate these special Pythagorean triples where each side of the triangle is a hypotenuse of another Pythagorean triple?

Edit: While the Euclidean formula for Pythagorean triples relies on the value of $p$ and $q$ to generate legs $a$ and $b$ with hypotenuse $c$, I am looking for a generalized way of finding the special "triple triples" for lack of a better term given integer inputs $(input_1...input_k)$ that I can input into functions $$f_A(input_1...input_k)=A$$ $$f_B(input_1...input_k)=B$$ $$f_C(input_1...input_k)=C$$ Where A and B are hypotenuses of other Pythagorean triples, and (A,B,C) forms a Pythagorean triple in and of itself.

  • $\begingroup$ What is your ultimate goal? You can write a program to generate millions of these. Anyway see sum of two squares for the information you need. $\endgroup$
    – WhatsUp
    May 10, 2022 at 4:14
  • $\begingroup$ The positive integers being the sum of at most two squares can easily be classified, but when a positive integer is the sum of two positive squares is a bit more complicated. At least you can check the necessary condition to find out whether $a,b$ can be the sum of two squares at all. One additional fact you can use is that one of $a,b$ must be divisible by $3$ and therefore divisible by $9$. $\endgroup$
    – Peter
    May 10, 2022 at 8:07
  • $\begingroup$ Ultimately, I am looking for a method of generating the sides of the special Pythagorean triple, given certain input variables. I want it to function in a similar way to Euclid's formula for regular Pythagorean triples (input P and Q to yield A,B, and C) but I'm not sure if I would need more than 2 inputs, or if this approach is even viable. $\endgroup$ May 10, 2022 at 8:58
  • $\begingroup$ If you want "three Pythagorean triples where the hypotenuses of the first two form the legs of the third", then you need $$p_1^2 + q_1^2 = h_1^2 \\p_2^2 + q_2^2 = h_2^2\\h_1^2 + h_2^2 = h_3^2$$ Combining gives $$p_1^2 + q_1^2 + p_2^2 + q_2^2= h_3^2$$ without any nested squaring. But that equation itself does not require the $p_i, q_i$ to be parts of Pythagorean triples, It is unclear to me if you are interested in solving the Pythagorean triple problem described, or your nested-squares problem, but the two are not the same. $\endgroup$ May 10, 2022 at 15:36
  • 2
    $\begingroup$ I guess looking at your table, you really do want solve the Pythagorean triple problem. But be aware that your nested squared equation is something different. Also note that the $P_i, Q_i$ in your table do not play the roles of $p_i, q_i$ in your description of the problem. Instead it is the $A_i, B_i$ that correspond to $p_i, q_i$. This inconsistent labelling makes it confusing to work out what you are doing. $\endgroup$ May 10, 2022 at 15:51

1 Answer 1


With Euclid's formula $\quad A=m^2=n^2\quad B=2mn\quad C=m^+n^2\quad a$ primitive Pythagorean triple with side-$A\,$ equal to the hypotenuse of any other triple can be generated using $\quad m=\dfrac{C+1}{2},\,n=\dfrac{C-1}{2}.\quad$ For example, with $\,(5,12,13),\,$ $C=13\longrightarrow m=7,\,n=6\longrightarrow F(7,6)=(13,84,85).$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .