If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
Finally we get to some Pytogrorean triangle. I'm only excited because right triangles are a common theme/section of PE.
Ok. I can teach you guys about how to genereate primitive Pytogrorean triples. But first, let's discuess the algorthim. We want to first generate primtive Pytogrorean triples. Then, we want multiples of this triplet. These multiples are right triangles. Hence, it will suffice the only condition that there is, EXCEPT the 1000 condition. That's enough. We create multiples until we reach above 1000.
So, now the meat of this problems. Primitive Pytogrorean triples are three positive integers that are coprimes with another. Essentially, $$ GCD(a, b, c) = 1 $$ $$ a^2 + b^2 = c^2 $$ How do we generate such a, b, c?
There are formulas $$ a = m^2 - n^2 $$ $$ b = 2mn $$ $$ c = m^2 + n^2 $$ Clearly, one can see that a can't be the greatest. However, it's not necessarily true that b > c, though the way I defined a, b, c tells us otherwise. Anyhow, if GCD(m, n) = 1. Then the resulting triplet number will be prime. But, we want p <= 1000. So how far should we go up? c has to be less than 1000, so m^2 + n^2 <= 1000, m < 31. Similary, a has to be positive so, m > n. We have our conditions, lets code it up!
Answer: 840
Runtime: 1.1 ms