[Math Lair] Generating Pythagorean Triples

Math Lair Home > Interactive content > Generating Pythagorean Triples

Here is a neat little formula for generating Pythagorean triples, which are positive integers which could form the side lengths of a right triangle.

For example, with m = 2 and n = 1, we get the familiar triangle with side lengths 3, 4, and 5. You can see that there is an infinite number of different Pythagorean triples, because the number of natural numbers is infinite.

Where a, b, and c have no common factors, the triple is called a fundamental Pythagorean triple or a primitive Pythagorean triple. It can be shown that, where m and n have no common factors and they are not both odd, the formula above generates a fundamental Pythagorean triple. This formula for generating Pythagorean triples was discovered by the Greek mathematician Diophantus around 250 A.D.

Here's a quick-and-dirty Java applet to quickly generate some Pythagorean triples. If you like Java applets, you may also want to check out my applet for Pascal's Art. Also visit cut-the-knot.org because they have some interesting ones.

Sorry, your browser does not appear to support Java.

View source code.

Here is a table of the first few numbers generated by this formula:
m n Leg X (m² − n²) Leg Y (2mn) Hypotenuse (m² + n²) Triangle Type
Primitive Composite
21345P1
3186102P1
4115817P2
512410262P4
61351237P3
714814502P7
3251213P4
421216204P1
52212029P5
623224408P1
72452853P6
4372425P7
531630342P2
632736459P1
734042582P5
5494041P8
642048524P4

See also Pythagoras.