1 package com.sam.twisters.euler; 2 /* 3 * A Pythagorean triplet is a set of three natural numbers, 4 * a < b < c, for which, 5 * a^(2) + b^(2) = c^(2) 6 * For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2). 7 8 * There exists exactly one Pythagorean triplet for which a + b + c = 1000. 9 * Find the product abc. 10 */ 11 public class Prog9 { 12 13 public static void main(String[] args) { 14 long startTime = System.nanoTime(); 15 /* 16 * For each possible pair of numbers below 1000 17 * check if there is a Pythagorean triplet for which a + b + c = 1000. 18 */ 19 for(int a=1;a<1000;a++){ 20 for(int b=1;b<1000;b++){ 21 for(int c=1;c<1000;c++){ 22 if(a*a == b*b+c*c && a+b+c == 1000){ 23 System.out.println(a*b*c); 24 } 25 } 26 } 27 } 28 29 long estimatedTime = System.nanoTime() - startTime; 30 System.out.println((float)estimatedTime/1000000000); 31 } 32 }