Same differences题号：135 难度： 45 中英对照

Given the positive integers, x, y, and z, are consecutive terms of an arithmetic progression, the least value of the positive integer, n, for which the equation, x2y2z2 = n, has exactly two solutions is n = 27:

342 − 272 − 202 = 122 − 92 − 62 = 27

It turns out that n = 1155 is the least value which has exactly ten solutions.

How many values of n less than one million have exactly ten distinct solutions?

Code

public final class p135 {
public static void main(String[] args) {
long start=System.nanoTime();
String result = run();
long end=System.nanoTime();
System.out.println(result);
System.out.println( (end-start)/1000000 + "ms" );
}

static public String run(){
final int LIMIT=1000000;
int[] solutions = new int[LIMIT];
for (int m = 1; m < LIMIT * 2; m++) {
for (int k = m / 5 + 1; k * 2 < m; k++) {
long temp = (long)(m - k) * (k * 5 - m);
if (temp >= solutions.length)
break;
solutions[(int)temp]++;
}
}

int count = 0;
for (int x : solutions) {
if (x == 10)
count++;
}
return Integer.toString(count);
}

}
4989
33ms