A $a\times b \times c$ cube formed by small $1^3$ cubes. If a laser beam travels along the diagonal of the cube, how many small cubes does it cross?

75 Views Asked by At

enter image description here

The way I am thinking about solving this problem is to use inclusion exclusion principle. Let $C_1$ be the number of boxes it crosses from the front side, $C_2$ be number of small boxes it crosses from the side, and $C_3$ number of boxes crossed from the top. Now we can get the desired number as $|C_1|+|C_2|+|C_3|-|C_1\cap C_2|-|C_1 \cap C_3|-|C_2\cap C_3|+|C_1\cap C_2 \cap C_3|=a+b+c-|C_1\cap C_2|-|C_1 \cap C_3|-|C_2\cap C_3|+|C_1\cap C_2 \cap C_3|$.

However, I am having trouble calculating the intersection sets. I thought about using the $\mathbb{gcd}$ but not sure how to translate my idea into a solution. Any help would be appreciated.

1

There are 1 best solutions below

3
On

Okay, So I ended up figuring out the answer so I'll just post it in case someone is interested.

First of all, reduce the problem to 2D by considering only one face of the cube (say the $a\times b$, the total number of cubes crossed is given by $a+b-\gcd(a,b)$. This also applies to the other two sides so we have a total of:

$a+b-\gcd(a,b)+a+c-\gcd(a,c)+b+c-\gcd(b,c)$.

But, here, we have double counted the ones where it crosses all 3 of sides, so we should subtract $a+b+c-\gcd(a,b,c)$. So adding all of this, we get $a+b+c-\gcd(a,b)-\gcd(b,c)-\gcd(a,c)+\gcd(a,b,c)$ as the final answer.