A Pythagorean triple is three positive integers with a2+b2=c2
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
generate every primitive Pythagorean triple from two numbers m and n, and prove that the formula gives them all;
use the divisibility facts about triples;
find every triple with a given leg or a given hypotenuse.
Rope with knots
Builders in many old cultures laid out a right angle with a rope knotted into 12 equal parts, pulled into a 3, 4, 5 triangle. The numbers 3,4,5 satisfy 32+42=52. So do 5,12,13 and 8,15,17. A tablet from Babylon, called Plimpton 322, lists many such triples, some with numbers in the thousands.
Three positive integers with a2+b2=c2 form a Pythagorean triple. It is primitive when gcd(a,b,c)=1. Any triple is a multiple of a primitive one: 6,8,10 is 2×(3,4,5).
The formula
Every primitive triple (with b the even leg) is
a=m2−n2,b=2mn,c=m2+n2,
where m>n>0, gcd(m,n)=1, and one of m, n is even.
Checking that these numbers work is algebra: (m2−n2)2+(2mn)2=m4+2m2n2+n4=(m2+n2)2.
Why the formula gives every primitive triple
Parity. In a primitive triple a and b are not both even. They are not both odd either: then c2=a2+b2≡2(mod4), which no square is. So one leg is even. Call it b. Then a and c are odd.
Factor.b2=c2−a2=(c−a)(c+a). Both factors are even. Write c+a=2u and c−a=2v, so (2b)2=uv.
Coprime. Any common factor of u and v divides u+v=c and u−v=a. Since gcd(a,c)=1, we get gcd(u,v)=1.
Squares. Two coprime numbers whose product is a square are both squares. So u=m2, v=n2.
Read off.c=u+v=m2+n2, a=u−v=m2−n2, b=2mn. Since a is odd, m and n have opposite parity.
A scatter plot of the primitive Pythagorean triples with hypotenuse below 100, with the odd leg across and the even leg upwards. Each of the sixteen dots is a triple such as (3, 4), (5, 12), (8, 15) drawn at (15, 8), and (65, 72). Dots with the same m lie on a curve labelled by m, from m = 2 to m = 9, and the quarter circle of radius 100 marks the limit.
Facts about every triple
In every Pythagorean triple:
one leg is a multiple of 3. A square is 0 or 1 modulo 3. If neither leg were a multiple of 3, then c2≡2.
one leg is a multiple of 4. In a primitive triple b=2mn, and one of m,n is even.
one of the three sides is a multiple of 5. A square is 0, 1 or 4 modulo 5, and the sums that are squares force a 0 somewhere.
So the product abc is always a multiple of 3×4×5=60, and 3,4,5 shows that 60 is best possible.
Triples with a given side
A given leg. Find every triple with a leg 12. Write 122=144=(c−b)(c+b). The two factors have the same parity and c−b<c+b. The pairs of even factors are 2×72, 4×36, 6×24 and 8×18. They give (c,b)=(37,35), (20,16), (15,9) and (13,5). So there are 4 triples: (12,35,37), (12,16,20), (9,12,15) and (5,12,13).
A given hypotenuse. A prime p is the hypotenuse of a primitive triple exactly when p≡1(mod4). For example 13=32+22 gives (5,12,13). In general, c is the hypotenuse of a primitive triple exactly when every prime factor of c is 1 modulo 4. If c has k different such primes, there are 2k−1 primitive triples with hypotenuse c.
Practise with new numbers
Try it in Python
The program lists the primitive triples with hypotenuse below 60 from the formula, and checks the list against a search over every pair of legs.
Common mistakes
Forgetting the conditions on m and n.m=3, n=1 gives (8,6,10), which is not primitive: m and n are both odd.
Missing the non-primitive triples. A question about "all triples" includes multiples such as (9,12,15).
Taking factor pairs of different parity. In (c−b)(c+b)=a2 the two factors must be both even or both odd.
Assuming the even leg is always the larger one. In (20,21,29) the even leg is the smaller.
Remember these
Primitive triples: m2−n2, 2mn, m2+n2, with m>n coprime and of opposite parity.
Every triple is k times a primitive one.
One leg is a multiple of 3, one leg of 4, one side of 5; so 60∣abc.
Given leg a: factor a2=(c−b)(c+b) into two factors of the same parity.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Which primitive triple comes from m=5, n=2?
Is (9,40,41) primitive? Which m and n give it?
Why is there no right triangle with integer sides and both legs odd?
Find a triple with hypotenuse 17.
How many triples have the leg 8?
References
David M. Burton, Elementary Number Theory, Chapter 12, section on the equation x2+y2=z2.
Enroll free in Diophantine Equations and Pythagorean Triples
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.