Project Euler: Problem 9

By | 18. April 2013

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

loop:
for (int a=1; a&lt;1000; a++) {
	for (int b=1; b&lt;1000;b++ ) {
		for (int c=1; c&lt;1000; c++) {
			if (a+b+c==1000&amp;&amp;c*c==a*a+b*b) {
				System.out.println(a);
				System.out.println(b);
				System.out.println(c);
				System.out.println(a*b*c);
				break loop;
			}
		}
	}
}

Lösung: 31875000

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.