-1

I am writing an algorithm to generate pythagorean triplets and I was going to use Euclid's theorem, however I have been unable to make it generate the first pythagorean triplet namely (3,4,5). Is this a limitation of the theorem? Does this occur for any higher values? I realise I am probably doing something stupid I appreciate the assistance.

stmfunk
  • 273

2 Answers2

2

Euclid's formula states that for any pair of integers $(m,n)$ with $m>n\geq1$, the triple $(a,b,c)=(m^2-n^2,2mn,m^2+n^2)$ is a Pythagorean triple.

The smallest choice for $n$ is $n=1$, and when $n=1$ the smallest choice for $m$ is $m=2$. Plugging those two values into Euclid's forumla gives:

$$(a,b,c)=(2^2-1^2,2\cdot 2\cdot 1,2^2+1^2)=(4-1,4,4+1)=(3,4,5).$$

Assuming you're using Euclid's formula correctly then it should be able to generate $(3,4,5)$.

David H
  • 29,921
2

I guess what you call Euclid's formula is $$A = 2mn, B = m^2- n^2 \mbox{ and } C = m^2+ n^2.$$ Setting $m=2$ and $n=1$ produces the Pythagorean triplet $(3,4,5)$.