The Math Forum

Ask Dr. Math - Questions and Answers from our Archives
Associated Topics || Dr. Math Home || Search Dr. Math

Formula for Pythagorean Triples

Date: 10/23/97 at 06:31:51
From: Tom Sunde
Subject: Formula for Pythagorean Triples

We have come across the formula for Pythagorean triples: 

   a = (m^2-n^2) 
   b = 2mn
   c = (m^2 + n^2)

Is this correct for absolutely all Pythagorean triples?
Can you find a specific triple with this formula?
Can m and n be any two numbers as long as they are positive?
Can you show us some examples?

We have found all the sequences for Pythagorean triples (odd numbers). 
The problem is that we have used our own method to find these. In our 
project we have to include the method. What is this method? We have 
never learned this at school.

Thanks for your help!

Date: 10/23/97 at 09:11:49
From: Doctor Chita
Subject: Re: Formula for Pythagorean Triples

Dear Tom:

Yes, you've discovered a very useful way to generate Pythagorean 

The conditions for it to work are that m and n are integers, and 
m > n. To generate some triples, make a table like this: 

m     n      2mn        m^2 - n^2        m^2 + n^2
2     1        4           3               5
3     1        6           8              10
3     2        12          5              13

You see from this table that you not only get primitive triples, like 
(3, 4, 5), but some multiples of them as well: (6, 8, 10). These two right 
triangles would be similar. 

Looking at the generators, you can also see why m has to be greater 
than n. For example, try m = 1 and n = 2 and see what happens.

Although this set of expressions is very useful, it does not give you 
all the triples. For example, the (9, 12, 15) triple can not be generated
using these expressions. Try it and see.

You will also notice other patterns in this table. Can all three 
numbers of a triple be even? odd? Why or why not?

Have fun playing with these triples. Since there's no limit to m 
and n, there is an infinite number of triples generated this way. 
How many can you generate up to m = 50? 

-Doctor Chita,  The Math Forum
 Check out our web site!   

Date: 10/23/97 at 09:22:35
From: Doctor Rob
Subject: Re: Formula for Pythagorean Triples

These formulas do give Pythagorean triples.  They do not give all of 
them, however.

If you want to find all Pythagorean triples, it suffices to find all
"primitive" Pythagorean triples, that is, ones such that the set 
{a,b,c} has greatest common divisor 1. Then any multiple d*a, d*b, and 
d*c will be another Pythagorean triple. 

The formulas you give are the ones which give primitive Pythagorean 
triples, provided appropriate restrictions are placed on m and n. 
First of all, if m and n have a common factor bigger than 1, then a, 
b, and c have the square of that factor in common, so the triple would 
not be primitive. Thus we must make the restriction that m and n be 
relatively prime. 

Furthermore, if m and n are both odd, then 2 is a divisor of a, b, and 
c, so the triple would not be primitive. Thus one of m and n must be 
odd and the other even.  

Lastly, we must have |m| > |n|, lest a < 0, and m and n have the same 
sign, lest b < 0. Since (-m,-n) gives the same Pythagorean triple as 
(m,n), we can assume that both m and n are positive. It turns out that 
these three conditions on m and n will guarantee that the triple is 

Thus the formulas that give all Pythagorean triples are these:

   a = d*(m^2 - n^2),
   b = 2*d*m*n,
   c = d*(m^2 + n^2),

where d is any positive integer, m > n > 0 are integers of opposite 
parity and relatively prime.


  The smallest allowable parameter values are m = 2, n = 1, d = 1. 
  They give a = 3, b = 4, c = 5. 

  Another allowable set of parameter values is m = 5, n = 2, d = 3. 
  They give a = 63, b = 60, c = 87.

If you are given a triple a, b, and c, you can find d, m, and n in the
following way. First of all, d = GCD(a,c). Then m = Sqrt[(c+a)/(2*d)] 
and n = Sqrt[(c-a)/(2*d)]. These are found by solving the first and 
last equations simultaneously for m^2 and n^2.


  Given the Pythagorean triple a = 28, b = 96, c = 100, we find
  that d = GCD(28,100) = 4, m = Sqrt[(100+28)/(2*4)] = Sqrt[16] = 4, 
  and n = Sqrt[(100-28)/(2*4)] = Sqrt[9] = 3. Sure enough, m > n > 0, 
  they are of opposite parity, and they are relatively prime.

You can make a table of primitive triples (d = 1) by starting with the
smallest example above. You increase m by one, and run through all
possible values for n satisfying the conditions (0 < n < m, n has 
opposite parity to m, and GCD(n,m) = 1). Repeat this until tired.  
This will give you the complete list of primitive Pythagorean triples.  
To get all Pythagorean triples, add to the list {d*a,d*b,d*c} for all 
d > 1.

 m    n    a    b    c
 2    1    3    4    5
 3    2    5   12   13
 4    1   15    8   17
 4    3    7   24   25
 5    2   21   20   29
 5    4    9   40   41
 6    1   35   12   37
 6    5   11   60   61
 7    2   45   28   53

Notice that a is always odd, b is always even, and c is always odd.
Notice that a may be either larger or smaller than b.

You may ask how these equations are derived. This works as follows.

Suppose {a,b,c} is a primitive Pythagorean triple. Then GCD(a,c) = 1, 
because otherwise that common factor would divide b, too, and the 
triple wouldn't be primitive. Similarly GCD(a,b) = 1 and GCD(b,c) = 1.  
Also a and b cannot both be odd, since if that happened, then a^2 and 
b^2 would leave remainder 1 when divided by 4, so c^2 = a^2 + b^2 
would leave remainder 2 when divided by 4. Then 2 would be a divisor 
of c^2, but 2^2 = 4 wouldn't, which is impossible. Thus one of a and b 
is even and the other is odd. Let b be the even one. Then c is odd, 

Rewrite the equation in the form b^2 = c^2 - a^2, divide both sides 
by 4, and factor, to get (b/2)^2 = [(c+a)/2]*[(c-a)/2]. Both (c+a)/2 
and (c-a)/2 are integers, because a and c are both odd, and b/2 is an 
integer because b is even. Furthermore GCD[(c+a)/2,(c-a)/2] = 1, since 
any common factor would divide their sum, c, and their difference, a, 
which have no common factor greater than 1. Since they are relatively 
prime, and their product is a square, it follows that each of them is 
a square. Let (c+a)/2 = m^2 and (c-a)/2 = n^2, where m > 0 and n > 0.  
Observe that m^2 > n^2, so m > n.  Also GCD(m^2,n^2) = 1, so 
GCD(m,n) = 1.  Finally, one of m^2 and n^2 is odd and the other even, 
since they are half the sum and difference of two odd numbers, so 
m and n have opposite parity.  Then

   c = m^2 + n^2, 
   a = m^2 - n^2,
   b = Sqrt[c^2 - a^2]
     = Sqrt[(c+a)*(c-a)]
     = Sqrt[(2*m^2)*(2*n^2)]
     = 2*m*n,

which are the formulas above that you found.

-Doctor Rob,  The Math Forum
 Check out our web site!   
Associated Topics:
High School Number Theory

Search the Dr. Math Library:

Find items containing (put spaces between keywords):
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.