If you paint the six sides of a 3x3x3 cube and then slice it into 27 unit cubes, how many will have paint on 0, 1, 2, 3 of their square sides?

Generalize to any dimension:

If you paint the sides of a n dimensional cube with sides length 3 and slice it into 3^{n} unit cubes, how many will have paint on 0, 1, 2, ..., n of their (n-1) dimensional sides?

0 sides = interior cubes = (n-2)^3

1 side = 6 sides * (n-2)^2 per side = 6(n-2)^2

2 sides = 12 edges *(n-2) per edge = 12(n-2)

3 sides = corners = 8

Checking, we see that this adds correctly:

n^3 -6n^2 + 12n + 8

6n^2 - 24n +24

12n - 24

8

----------------------------

n^3

/***********************************/

oops. Misread the problem. I obviously answered for a 3 dimensional cube of side n.

*Edited on ***March 5, 2015, 3:03 pm**