# Direct from Dell

Euler problem 9.2

.

There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

```g p =
[ [a, b, c]
| m <- [2 .. limit],
n <- [1 .. (m - 1)],
let a = m ^ 2 - n ^ 2,
let b = 2 * m * n,
let c = m ^ 2 + n ^ 2,
a + b + c == p
]
where
limit = floor . sqrt . fromIntegral \$ p
```

.

Euclid’s formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers $m$ and $n$ with $m > n > 0$. The formula states that the integers

$\displaystyle{ a=m^{2}-n^{2},\ \,b=2mn,\ \,c=m^{2}+n^{2}}$

form a Pythagorean triple. The triple generated by Euclid’s formula is primitive if and only if $m$ and $n$ are coprime and one of them is even. When both $m$ and $n$ are odd, then $a$, $b$, and $c$ will be even, and the triple will not be primitive; however, dividing $a$, $b$, and $c$ by 2 will yield a primitive triple when $m$ and $n$ are coprime.

Every primitive triple arises (after the exchange of $a$ and $b$, if $a$ is even) from a unique pair of coprime numbers $m$, $n$, one of which is even.

— Wikipedia on Pythagorean triple

— Me@2022-12-10 09:57:27 PM

.

.