This is already a post from comp.lang.prolog. But it seems it is reasonably challenging and could be fun. So I am also crossposting here.

It took Deep Thought 7½ million years to compute and check the answer, which turns out to be 42. But can we also compute via Prolog positive integer numbers x, y and z such that:

```
x^3 + y^3 + 42 = z^3
```

When I use a nearly quadratic algorithm, I can compute k=87. Here is an example code that does the computation and the time measurement is from a slow Mac laptop:

```
?- time((above(0,S), H is S//2, between(0,H,X),
Y is S-X, C is X^3+Y^3+87, rootrem(C,3,Z,0))).
% Up 70,783 ms, GC 612 ms, Threads 69,768 ms (Current 09/17/19 21:31:34)
X = 1972,
Y = 4126,
Z = 4271
```

Other practical ways to speed up a Prolog solution so that we could reach k=42, or is this out of reach concerning computing time?

**Edit 18.09.2019:**

SWI-Prolog timing:

```
?- time((between(0,inf,S), H is S//2, between(0,H,X),
Y is S-X, C is X^3+Y^3+87, nth_integer_root_and_remainder(3,C,Z,0))).
% 37,217,891 inferences, 25.142 CPU in 25.408 seconds (99% CPU, 1480280 Lips)
X = 1972,
Y = 4126,
Z = 4271
```