Fill a cube with small cubes with different integer side lengths We are given two (potentially unlimited) sets of cubes, say red cubes (with side $n$) and white cubes (with side $m$), with $m,n \in \mathbb{N} \setminus \{0\}, m \neq n$ (let's assume $n>m$).
Using the same number of red and white cubes, "build" a bigger cube, in the sense that this bigger cube is tessellated with the small cubes.
What is the minimum length $\mathfrak{L}_{n,m}$ of the side of the big cube (as a function of $m$ and $n$)? (How many small cubes are used?)
As noted by @achillehui, we have
$$ \mathfrak{L}_{an,am} = a \mathfrak{L}_{n,m}, \quad a \in \mathbb{N} \setminus \{0\},$$
so it suffices to consider the case $\text{gcd}(n,m)=1.$


*

*$\mathfrak{L}_{n,m}^1 = \text{lcm}(l,\frac{L}{l^2}(m^3 + n^3))$ is a solution (check my answer below for the details)

*$\mathfrak{L}_{n,m}^2 = n (m^3 + n^3)$ is a solution (due to @Logophobic)

*$\mathfrak{L}_{n,m}^3 = m (m^3 + n^3)$ and $\mathfrak{L}_{n,m}^4 = 2m (m^3 + n^3)$ are solutions for some pairs $(n,m)$.
None of them is minimal, since we have
$$ \mathfrak{L}_{4,2}^1 = 36, \quad \mathfrak{L}_{4,2}^2 = 288 $$
while $\mathfrak{L}_{4,2} = 12$ is also a solution.
 A: I write here what I have in mind; this shows that there exists a solution for all pairs $(n,m)$.


*

*Step 0: Let


$$ l = \text{lcm}(m,n) \\ L= \text{lcm} \left( \frac{l^2}{m^2},\frac{l^2}{n^2} \right)    \\ \mathfrak{L} = \text{lcm} \left(l, \frac{L}{l^2} (m^3 + n^3) \right)   $$


*

*Step 1: Let us denote by $C_1$ a square cuboid of size $l \times l \times n$, made of $(l/n)^2$ red cubes.

*Step 2: Let us denote by $C_2$ a square cuboid of size $l \times l \times m$, made of $(l/m)^2$ white cubes.

*Step 3: Square cuboid $C_3$ is made by stacking up some $C_1$'s so that it contains L red cubes. In order to do this, we stack up $ \frac{L}{\frac{l^2}{n^2}} = \frac{L n^2}{l^2}$ cuboids $C_1$; since the heigth of $C_1$ is $n$, $C_3$ has dimensions
$$ l \times l \times \frac{L n^3}{l^2} $$


*

*Step 4: Analogously to Step 3, square cuboid $C_4$ is obtained by stacking up $\frac{L m^2}{l^2}$ cuboids $C_2$, contains $L$ white cubes and has dimensions


$$ l \times l \times \frac{L m^3}{l^2} $$


*

*Step 5: now we stack up one cuboid $C_3$ and one cuboid $C_4$ and this gives cuboid $C_5$; $C_5$ contains $2 L$ cubes ($L$ red and $L$ white) and has dimensions


$$ l \times l \times \left( \frac{L n^3}{l^2} + \frac{L m^3}{l^2} \right) = l \times l \times \frac{L }{l^2} (m^3 + n^3)$$


*

*Step 6: Using $$\frac{\mathfrak{L}}{l} \cdot \frac{\mathfrak{L}}{l} \cdot \frac{\mathfrak{L}}{\frac{L }{l^2} (m^3 + n^3)} $$ cuboids $C_5$, we can build the big cube, with dimensions $\mathfrak{L} \times \mathfrak{L} \times \mathfrak{L}$. This cube contains $$ \frac{\mathfrak{L}}{l} \cdot \frac{\mathfrak{L}}{l} \cdot \frac{\mathfrak{L}}{\frac{L }{l^2} (m^3 + n^3)} \cdot 2L = \frac{2 \mathfrak{L}^3}{m^3 + n^3} $$ small cubes (half red and half white).



Case $(n,m)=(3,2)$
Here is what we get when $n=3$ and $m=2$ are put into the solution.


*

*We have $l=6, L=36, \mathfrak{L}=210$.

*Cuboid 3: $6 \times 6 \times 27$, made of 36 red cubes.

*Cuboid 4: $6 \times 6 \times 8$, made of 36 white cubes.

*Cuboid 5: $6 \times 6 \times 35$, made of 36 red cubes and 36 white cubes (cuboid 3 + cuboid 4)

*Cube: $210 \times 210 \times 210$, using $7350 (=35 \cdot 35 \cdot 6)$ cuboids 5; there are $264600 (=7350 \cdot 36)$ white cubes and $264600$ red cubes.

Case $\text{GCD}(m,n)=1$
If $m$ and $n$ are coprime, then the expression can be simplified
$$ l = mn, \quad L= m^2 n^2, \quad \mathfrak{L}=m n (m^3 + n^3) $$
$ 2 m^3 n^3 (m^3 + n^3)^2$ cubes are used ($m^3 n^3 (m^3 + n^3)^2$ for each color).

Case $n=a m$
$$ l = n, \quad L= a^2, \quad \mathfrak{L}= n (1 + a^3) $$
$ 2 n^3 \left(1 + \left(\frac{n}{m}\right)^3\right)^2$ cubes are used ($n^3 \left(1 + \left(\frac{n}{m}\right)^3\right)^2$ for each color).
