Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.

A Pythagorean triplet is a set of three natural numbers, a b c, for which,

a^{2} + b^{2} = c^{2}

For example, 3^{2} + 4^{2} = 9 + 16 = 25 = 5^{2}.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc.

**********

The wikipedia page on Pythagorean triple is helpful in solving this problem. Particularly the part about

Euclid’s formula: a = m^{2} – n^{2}, b = 2mn, c = m^{2} + n^{2}.

Helpful link:

Pythagorean triple – http://en.wikipedia.org/wiki/Pythagorean_triple

### One Possible Solution: Java

public class Problem_09 { public static void main(String [] args){ for (int n = 1; n < 500; n++) { for (int m = (n + 1); m < 500; m ++) { int a = (m * m) - (n * n); int b = 2 * m * n; int c = (m * m) + (n * n); if (a + b + c == 1000) { int product = a * b * c; System.out.format("a = %d" + "b = %d" + "c = %d" + newline, a, b, c); System.out.format("Product = %d" + newline, product); } } } } public static String newline = System.getProperty("line.separator"); }

### One Possible Solution: Python

import math def main(): """Main program""" for n in xrange(1, 500): for m in xrange(n + 1, 500): a = int(math.pow(m, 2) - math.pow(n, 2)) b = 2 * m * n c = int(math.pow(m, 2) + math.pow(n, 2)) if a + b + c == 1000: product = a * b * c print "a = %d, b = %d, c = %d" % (a, b, c) print "Product = %d" % (product) if __name__ == '__main__': main()