[] 纯文本查看 复制代码
/*
* 1: x + 100 = m ^ 2; ===> m > 10
* 2: m ^ 2 + 168 = n ^ 2; ===> n > m > 10(由1、2得)
* 3: 168 = 2 * 2 * 2 * 3 * 7;
* 4: (n - m)(n + m) = 168; ===> n + m > 20(由1、4得)
* 5: 168 ===> 2 * 84、3 * 56、4 * 42 、6 * 28、7 * 24、8 * 21(由4、5得)
* 如 n - m = 2; n + m = 84; 两式联立得2n = 84 + 2; m = n - 2 求得 m ,n 并满足n ^ 2 - m ^ 2 = 168
*/
package com.leo.exercise;
public class Test{
public static void main(String[] args) {
int[] array = {2, 84, 3, 56, 4, 42, 6, 28, 7, 24, 8, 21};
int n = 0, m = 0;
for(int i = 0; i < array.length; i += 2){
n = (array[i] + array[i + 1]) / 2;
m = array[i + 1] - n;
if(n * n - m * m == 168){
System.out.println(m * m - 100);
}
}
}
}