Scroll down to see how it works. If you'd rather solve the problem yourself, don't scroll. . . . . . How it works (this is a spoiler): ========================================= We have 3 main variables - a, b, and c. a and b are looped for the values 1 to 500*, so that we get every possible pair. c is then set to the square root of a^2 + b^2 (as per Pythagorean theorem). For each set of values for a, b, and c, we have to check to see if they are the special triplet. The numbers must total 1000 and c must be a whole number for it to be the special triplet. Interestingly, there is no real need to check if c is a whole number. We already know that a and b are whole numbers, and we already checked to see if the total is 1000. If it is, then we know c must be a whole number and we have found our triplet. The final step is simply to find the product of a, b, and c (once we have our special triplet) to get the answer the problem is looking for. * We use 500 because the numbers must total 1000. Using a higher number would be pointless, because even if the other value - either a or b - was ridiculously tiny, the total of either a or b and the hypotenuse (which must make it "back" to where either a or b started) will already be greater than 1000.
The @ProjectEuler account is created and maintained by @PullJosh. If you have questions, feel free to comment here or on my @PullJosh profile page for a much quicker response.