# How many cubes are crossed by a diagonal?

A cuboid is composed by $81 \times 125 \times 128$ cubes. How many cubes are crossed by a (main) diagonal of the cuboid?

(note: I chose the numbers for the sides so that the case of the diagonal passing through a vertex of an inner cube is not possible)

Suppose we

move along the diagonal, parameterizing our movement by a number t that runs from 0 at one corner to 1 at the opposite corner.

Then

we enter a new cube every time one of 81t, 125t, 128t crosses an integer. These all happen at different times except that at the very start (t=0) all three happen together but we are entering only a single cube.

So the total number of cubes is

81+125+128-2 = 332.

Here's another way of saying it that some may find more congenial:

Consider the planes, parallel to the sides of the cuboid, that divide it into those cubes. As we travel from one corner to the other, we enter a new cube every time we cross one of those planes. There are 80+124+127=331 planes in all; plus the one cube in which we start, for a total of 332 cubes.

• You have to note that $\gcd(81,125,128)=1.$ Nov 24 '18 at 1:44
• OP already did, in effect. "note: I chose the numbers for the sides so that the case of the diagonal passing through a vertex of an inner cube is not possible". Nov 24 '18 at 1:56
• And, actually, so did I: "These all happen at different times except that at the very start (t=0) all three happen together". I mean, neither OP nor I used the words "greatest common divisor", but that's what we were both referring to. Incidentally, what matters isn't quite that gcd(81,125,128)=1 but that those three numbers are pairwise coprime. Nov 24 '18 at 1:58