Not all values are possible

If you calculate the sequence z^3 modulo 9 you get [1,8,0,1,8,0,1,8,0,...]. This repeats indefinitely. You can show this by considering the expression (3n+k)^3 mod 9, where 0<=k<=2. This expands to:

(3n)^3+3.(3n)^2k+3.(3n)k^2+k^3 mod 9.

The first three terms are all multiples of 9, so the remainder will be k^3 mod 9 which is [1,8,0] as we showed above. The possible remainders when x^3+y^3+z^3 is divided by 9 can be obtained by adding all the combinations of three remainders taken from this list. This gives: [0,1,2,3,8,9,10,16,17,24], which when reduced modulo 9 becomes [0,1,2,3,8,0,1,7,8,6].

We can expand these sums into a table, k1 down the column and (k2,k3) across:


We can now count how many of the 27 combinations add up to each possible sum (0-8). The result is shown in the following table. This allows us to infer some additional constraints on 'z':

TotalCombinationsCountConstraints on 'z'
0(0,0,0), (0,1,8)7none
1(0,0,1), (1,1,8)6none
2(0,1,1)3z mod 3 can't be 2
3(1,1,1)1z mod 3 must be 1
6(8,8,8)1z mod 3 must be 2
7(0,8,8)3z mod 3 can't be 1
8(0,0,8), (1,8,8)6none

Distribution of modulo value

It is quite difficult to generate a graphic showing how these modulo values are distributed throughout space, but we can hone in on the values close to the surface V(x,y,z)=x^3+y^3-z^3=0. We can define the function Zv(x,y), which returns the largest z value where V is positive. There are tools on the 2D mapping page that will let you visualise the distribution of Zv values. One of these allows you to plot the distribution of Zd modulo 9. Near the origin this looks like:

The map seems to be divided into three types of zone, separated by the contour lines, corresponding to increasing values of n=z-x.

There are three patterns:

n mod 3 = 0 n mod 3 = 1 n mod 3 = 2

The rarest values, 3 (green) and 6 (blue) only occur in a single band.


On the Numberphile page we discussed finding cube sums using an algorithm described by "numberphile" youtube. Here we look at the distribution of solutions that can be found using the algorithm when the equation doesn't have integer roots in the hope that they will be similarly small compared with the target.

The original pages searches for solutions of x^3+y^3+z^3=k by trying 'z' values and looking for solutions for x and y. Here we use the same search algorithm but relax the rules for x and y, this allows us to find solutions for other 'k' values. The hope is that this will be more efficient at finding solutions for small k than the more systematic algorithm that just tries all x and y values.

The numbers found are plotted on a 81x81 grid as the answers seem to depend on base 9.

Choose a range of 'k' values to search.

Target Start: End: Max Z:


Other pages

(c) John Whitehouse 2021