pythagorean triples exercise

BartC bc at
Mon Oct 25 01:56:16 CEST 2010

"Tim Roberts" <timr at> wrote in message
news:5na7c6dlv0qii3pta58as50lmjcrrtk6l3 at
> Baba <raoulbia at> wrote:

>>a^a + b^b = c^c is the condition to satisfy
> No, it's not.  It's a^2 + b^2 = c^2, where a, b, and c are integers.
> Perhaps you meant a*a + b*b = c*c.

Or possibly a**2 + b**2 = c**2

>>and i need to use loops
>>and "n" will be an upper limit of one (or more?) of the loops but i am
>>a bit lost. Please help me get thinking about this right.
> The simplest (but not most efficient) method is brute force, using three
> loops, one each for a, b, and c.  You can compute the largest "c" you will
> need by computing the square root of a*a+b*b.

If square roots have to be used, you might as well use the two-loop
algorithm, as you're nearly there.

A simpler estimate for the largest c is just a+b, although it might involve 
a few extra iterations.


More information about the Python-list mailing list