Sujet : Re: 61. - THE SILVER CUBES
De : ilan_no_spew (at) *nospam* hotmail.com (IlanMayer)
Groupes : rec.puzzlesDate : 19. Jul 2025, 03:46:13
Autres entêtes
Organisation : novaBBS
Message-ID : <da38f2628fe7919ad1a2f3495eeb2483@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
On Tue, 15 Jul 2025 8:19:38 +0000, David Entwistle wrote:
On Sat, 12 Jul 2025 23:14:47 -0000 (UTC), Richard Tobin wrote:
>
The first solution can be found in seconds with a fairly straighforward
program. Obviously Dudeney didn't do that.
>
I tried the programmatic approach and didn't find a solution in seconds,
nor even minutes - I was probably doing a lot of unnecessary looping.
I've
looked at the solution and the common denominator has five digits.
>
The other path looks to be the way to go.
The C# program below finds the solution in under a minute:
using System;
namespace SumOfCubes
{
class SumOfCubes
{
private const long MAX = 200000;
static void Main(string[] args)
{
if (args.Length == 1 && long.TryParse(args[0], out long
number) && number > 0)
{
FindCubes(number);
}
else
{
Console.WriteLine("Usage: SumOfCubes <number>");
}
}
private static void FindCubes(long number)
{
double third = 1.0 / 3.0;
bool found = false;
for (long a = 1; a < MAX && !found; a++)
{
long a3 = a * a * a;
for (long b = a; b < MAX && !found; b++)
{
long sum = a3 + b * b * b;
long c3 = sum / number;
if (c3 * number == sum)
{
long c = (long)Math.Round(Math.Pow(c3, third));
if (c * c * c == c3 && GCD(a, c) == 1 && GCD(b,
c) == 1)
{
Console.WriteLine($"({a} / {c})^3 + ({b} /
{c})^3 = {number}");
found = true;
}
}
}
}
}
private static long GCD(long number1, long number2)
{
long remainder;
while (number2 != 0)
{
remainder = number1 % number2;
number1 = number2;
number2 = remainder;
}
return number1;
}
}
}
--