By a double-counting argument on the individual surfaces, we need to use each of them exactly once when forming the $n$ cubes of a given color.
Think about the individual faces and their pairings that you need. For a color $A$, we want:
- 8 corner cubes with $A-A-A$ meeting at a corner
- $12(n-2)$ edge cubes with $A-A$ meeting at a side
- $6(n-2)^2$ surface cubes with $A$ on a side.
- $(n-2)^3$ internal cubes that we don't care about the colors (and from above cannot have color $A$ on them).
If we have such cubes, then we obviously can put together the cube of color $A$. Hence, the question boils down to if we can color the $n^3$ cubes in such a manner.
Let's investigate how to form a unit cube: To form the 6 sides of a cube, we could pair up distinct colors in the following ways:
- 2 corners: $A-A-A$ and $B-B-B$
- 3 edges: $A-A, B-B, C-C$
- 1 corner, 1 edge, 1 surface: $A-A-A, B-B, C$
- 2 edges, 2 surfaces: $A-A, B-B, C, D$
- 1 edge, 4 surfaces: $A-A, B, C, D, E$
- 6 surfaces: $A, B, C, D, E, F$
Note that for $n = 3, 4$, we can't use the cubes with more than $n$ colors.
Let's consider $n=2$.
We want 8 corner cubes for individual colors, and we can make each cube a "2 corner" cube hence we are done.
Let's consider $n=2$.
We know there is a solution of:
- 3 of 2 corners. For a given color $A$, this creates 2 corner cubes and 1 internal cube.
- 18 of 1 corner, 1 edge, 1 surface. For a given color $A$, this creates 6 corner cubes, 6 edge cubes, and 6 surface cubes.
- 6 of 3 edges. For a given color $A$, this creates 6 edge cubes.
How can we find this solution on 27 cubes?
Let's make a simplifying (but unnecessary) assumption that the cubes have cyclic symmetry in colors. This means that for each cube type, we have a multiple of 3 of them, corresponding to cycling though the 3 colors.
If we use $3a$ of 2 corners, $3b$ of 1 corner, 1 edge, 1 surface, and $3c$ of 3 edges, then for a given color $A$, we will have
- Corners: $2a + b = 8$
- Edges: $b + 3c = 12$
- Surfaces: $b = 6$
- Internal: $a = 1$
- Total cubes: $a+b+c = 9$
This yields the unique consistent system $ a = 1, b = 6, c = 2$, which matches the above.
In fact, this is the unique solution (up to various isomorphisms of coloring these cubes), even if we relax the unnecessary assumption.
Let's deal with $n=4$
Again we make the simplifying assumption that the cubes have cyclic symmetry in colors. If we use $4a$ of 2 corners, $4b$ of 1 corner, 1 edge, 1 surface, and $4c$ of 3 edges, $4d$ of 2 edges, 2 surfaces then for a given color $A$, we will have
- Corners: $2a + b = 8$
- Edges: $b + 3c +2d = 24$
- Surfaces: $b +2d = 24$
- Internal: $2a + b + c = 8$
- Total cubes: $a+b+c+d = 16$
This yields multiple integer solutions. EG If we set $c = 0$, we have $ 0 \leq a \leq 4, b = 8 - 2a, d = a+8$.
Let's deal with $n \geq 5$
Again we make the simplifying assumption that the cubes have cyclic symmetry in colors. If we use $na$ of 2 corners, $nb$ of 1 corner, 1 edge, 1 surface, and $nc$ of 3 edges, $nd$ of 2 edges, 2 surfaces, and $ne$ of 1 edge, 4 surfaces, then for a given color $A$, we will have
- Corners: $2a + b = 8$
- Edges: $b + 3c +2d+e = 12(n-2)$
- Surfaces: $b +2d+4e = 6(n-2)^2$
- Internal: $(n-2)a + (n-3)b + (n-3)c + (n-4)d + (n-5)e = (n-2)^3$
- Total cubes: $a+b+c+d+e = n^2$
This has solutions like $ a = 1, b = 6, c = e - (n-5)(2n-6), d = 3(n-1)(n-2) - e, e = e$.
In particular, we don't need to use the "6 surface" cube.