// you’re reading...

Math

Generating Pythagorean Triples

Pythagorean triples

Pythagorean triples consists of three positive integers a, b, and c, such that a2 + b2 = c2. These triples are commonly written as (a, b, c), and a typical example is (3, 4, 5); 32 + 42 = 52 or 9 + 16 = 25.
A primitive Pythagorean triple is one in which a, b and c are coprime (gcd(a, b, c) = 1) and for any primitive Pythagorean triple, (ka, kb, kc) for any positive integer k is a non-primitive Pythagorean triple.

Euclid’s formula (300 BC) will generate Pythagorean triples given an arbitrary pair of positive integers m and n with m > n > 0. A primitive Pythagorean triple additionally require:

  • m and n have opposite parity – i.e. if one is odd, the other must be even.
  • m and n are coprime – i.e. they have no common integer factors greater than 1.
  a=m^2-n^2, b=2mn \mbox{ and } c=m^2+n^2

It’s easy to check algebraically that the sum of the squares of the first two is the same as the square of the last one.

Below is a table of [a, b, c] for n between 1 and 9 and m between 2 and 10.
The highlighted cells show primitive Pythagorean triples (GCD(a, b, c) = 1).

n =

1

2

3

4

5

6

7

8

9
m ↓
2

[3,4,5]
3

[8,6,10]

[5,12,13]
4

[15,8,17]

[12,16,20]

[7,24,25]
5

[24,10,26]

[21,20,29]

[16,30,34]

[9,40,41]
6

[35,12,37]

[32,24,40]

[27,36,45]

[20,48,52]

[11,60,61]
7

[48,14,50]

[45,28,53]

[40,42,58]

[33,56,65]

[24,70,74]

[13,84,85]
8

[63,16,65]

[60,32,68]

[55,48,73]

[48,64,80]

[39,80,89]

[28,96,100]

[15,112,113]
9

[80,18,82]

[77,36,85]

[72,54,90]

[65,72,97]

[56,90,106]

[45,108,117]

[32,126,130]

[17,144,145]
10

[99,20,101]

[96,40,104]

[91,60,109]

[84,80,116]

[75,100,125]

[64,120,136]

[51,140,149]

[36,160,164]

[19,180,181]

Afterthoughts

  • Euclid of AlexandriaEuclid of Alexandria is the most prominent mathematician of antiquity best known for his treatise on mathematics The Elements. The long lasting nature of The Elements must make Euclid the leading mathematics teacher of all time. However little is known of Euclid’s life except that he taught at Alexandria in Egypt.

Discussion

7 Responses to “Generating Pythagorean Triples”

  1. Why is it so difficult for people to see the easy way to get Pythagorean triples?
    Taka any odd number and square it
    5 for example so we get 25
    The other 2 sides of the triangle must be consecutive numbers
    that add up to 25, so 12,13
    then 5,12,13 is the triple

    9 squared is 81

    two consecutive numbers that add to 81 are 40 and 41

    so 9,40,41
    etc no need for a fancy formula.

    Posted by Alfred McLaughlan | April 29, 2025, 5:41 AM
  2. What is the relationship between Pythagoras,Plato and Euclid Sir.

    Posted by Babu.K | October 26, 2020, 6:23 AM
    • If you start with an even number like 8 for examople

      8 square is is 64 you must divide that by 2

      32 and the two odd numbers which are consecutive and add up to 32 are 15 and 17

      12 squared is 144

      divide by 2 is 72

      two consecutive odd numbers that add to 72 are 35 and 37 etc

      Posted by Alfred McLaughlan | April 29, 2025, 5:57 AM
  3. It’s in there as 15,8,17 and 35,12,37, which are the same thing.

    Posted by Krystal | August 29, 2020, 12:03 AM
  4. Euclid’s formula cannot apparently identify triples where b is odd (e.g.8,15,17 or 12,35,37

    Posted by Robert Brown | July 18, 2020, 11:29 PM
  5. Love the table of Pythagorean Triples. First example I’ve seen of triples, using Euclid’s formula, that shows the actual integers for m and n, and the resulting triple.

    Great piece if work.

    Posted by Robert Hock | January 31, 2017, 4:36 PM

Reply to Alfred McLaughlan