看看下面的代码
Find how many Cardano Triplets exist such that a+b+c<=n
该功能是找出总的cardano三元组,帮助我优化它以获得更大的值整数
private static boolean isTrue(long a, long b, long c) { long res = ((8 * a * a * a) + (15 * a * a) + (6 * a) - (27 * b * b * c)); //double res=((Math.cbrt(a+(b*Math.sqrt(c))))+(Math.cbrt(a-(b*Math.sqrt(c))))); return res == 1; }
3.以下函数返回三元组函数isTrue(...)
并更新全局计数器变量private static int counter=0;
private static long countCardano(long n) {
long c;
boolean b;
for (long i = 2; i <= n; i++) {
for (long j = 1; j <= n; j++) {
for (long k = 5; k <= n; k++) {
if ((i + j + k) <= n) {
if (isTrue(i, j, k)) {
//System.out.println("("+i+","+j+","+k+")");
counter++;
}
}
}
}
}
return counter;
}