Sujet : Re: 61. - THE SILVER CUBES
De : richard (at) *nospam* cogsci.ed.ac.uk (Richard Tobin)
Groupes : rec.puzzlesDate : 19. Jul 2025, 15:22:06
Autres entêtes
Organisation : Language Technology Group, University of Edinburgh
Message-ID : <105g9me$1km2n$1@artemis.inf.ed.ac.uk>
References : 1 2 3 4
User-Agent : trn 4.0-test76 (Apr 2, 2001)
In article <da38f2628fe7919ad1a2f3495eeb2483@
www.novabbs.com>,
IlanMayer <
ilan_no_spew@hotmail.com> wrote:
The C# program below finds the solution in under a minute:
Here is a C program. You can choose whether to use floating point
(which should be big and accurate enough) but it you don't you will
need to check whether you have the flsll function.
/* Find rationals a/d and b/d the sum of whose cubes is 17 */
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <inttypes.h>
#include <math.h>
/* integer cube root, return -1 if not a cube */
long long int cuberoot(long long c)
{
#ifdef USE_FLOAT
long long a = cbrt(c);
#else
int n = flsll(c);
long long a = 1ll << ((n+2)/3); /* a good first approximation */
while(c/a/a < a)
a = (2*a+c/a/a) / 3;
#endif
return a*a*a == c ? a : -1;
}
int main(int argc, char **argv)
{
int n = (argc > 1 ? atoi(argv[1]) : 17);
long long denom, denom3n, num1, num2, num13, num23;
for(denom=1; denom<1000000; denom++)
{
if(denom % 1000 == 0)
printf("(%lld)\n", denom);
denom3n = denom * denom * denom * n;
for(num1=1; ; num1++)
{
num13 = num1 * num1 * num1;
num23 = denom3n - num13;
if(num23 < num13)
break;
num2 = cuberoot(num23);
if(num2 != -1)
{
printf("%lld^3 + %lld^3 = %d x %lld^3\n",
num1, num2, n, denom);
return 0;
}
}
}
}