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)],leta = m ^ 2 - n ^ 2,letb = 2 * m * n,letc = m ^ 2 + n ^ 2, a + b + c == p ]wherelimit = floor . sqrt . fromIntegral $ p

— based on *Haskell official*

.

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

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

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

— Wikipedia on *Pythagorean triple*

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

.

.

2022.12.11 Sunday (c) All rights reserved by ACHK

You must be logged in to post a comment.