已知 a^2+b^2=c^2(a,b,c 为自然数,a<b<c),且a+b+c=1000,求abc的值?
public static int getABC() { int resVal = 1; for (int a = 0; a <= 1000; a++) { for (int b = 1; b <= 1000; b++) { for (int c = 2; c <= 1000; c++) { if (a * a + b * b == c * c && a + b + c == 1000 && a < b && b < c) { resVal = a * b * c; System.out.println("[a = " + a + ", b = " + b + ", c = " + c + "]"); System.out.println("=> a^2 + b^2 = " + (a * a + b * b) + " = c^2 = " + c * c); System.out.println("=> a + b + c = " + (a + b + c)); System.out.println("=> a * b * c = " + (a * b * c)); } } } } return resVal; } public static void main(String[] args) { getABC(); }
结果:
[a = 200, b = 375, c = 425]
=> a^2 + b^2 = 180625 = c^2 = 180625
=> a + b + c = 1000
=> a * b * c = 31875000