67,513
社区成员
发帖
与我相关
我的任务
分享
public class Ternary {
public static void main(String[] args) {
long start = System.currentTimeMillis();
System.out.println(count(1, 50000));
long end = System.currentTimeMillis();
System.out.println(end - start);
}
private static long count(int a, int b) {
long resultCount = 0;
int tempCount = 0;
for (int n = a; n <= b; n++) {
for (int y = 1; y * y <= n; y++) {
if (n % y == 0) {
int t = n / y;
int k = t + y;
if ((k & 3) == 0) {
if (y > (k >>= 2)) {
tempCount++;
}
if (t != y && t > k) {
tempCount++;
}
}
}
}
resultCount += (tempCount - 1) * tempCount >> 1;
tempCount = 0;
}
return resultCount;
}
}