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.
>Fuck it I'll brute force it
public class PythagoreanTriplet
{
int a = 0;
int b = 0;
int c = 0;
public PythagoreanTriplet()
{
for(int i = a; i < 1000; i++)
{
for(int j = b; j < 1000; j++)
{
for(int k = c; k < 1000; k++)
{
if(checkIfTriplet(i, j, k))
{
a = i;
b = j;
c = k;
return;
}
}
}
}
}
private boolean checkIfTriplet(int a, int b, int c)
{
if(a + b + c != 1000)
return false;
if(!(a < b && b < c))
return false;
if(!(a * a + b * b == c * c))
return false;
return true;
}
public int getProduct()
{
return a * b * c;
}
public static void main(String[] args)
{
System.out.println((new PythagoreanTriplet().getProduct()));
}
}