Well, problem number 9 was an interesting return to the world of Pythagoras. If you haven't looked at the riddle, here it is:
Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.
OK. The first thing we know is that a2 + b2 = c2 is Pythagorean Theorem.
Now to find Pythagorean Triplets with positive whole numbers(natural numbers) we could try iterating through the infinite set of number until we found the right set or we could use this formula:
a = 2mn
b = m2 - n2
c = m2 + n2
where m > n > 0
So now we have:
1000 = a + b + c
1000 = (2mn) + (m2 - n2) + (m2 + n2)
1000 = 2mn + 2m2 + 0
500 = mn + m2
500 = m(n + m)
(500/m) = n + m
(500/m) - m = n
You now have what you need to write a program to find your triplet. I'll give you my inplementation later.
1000 = (2mn) + (m2 - n2) + (m2 + n2)
1000 = 2mn + 2m2 + 0
500 = mn + m2
500 = m(n + m)
(500/m) = n + m
(500/m) - m = n
You now have what you need to write a program to find your triplet. I'll give you my inplementation later.