Example 7.15 Given $m$ colors, use these colors to paint the 6 faces of a cube, with each face painted one color. Find the number of distinct colorings of the cube $g(m)$.
Let $A$ denote the set of the 6 faces of a cube, and $B$ denote the set of $m$ colors. Let $(D, *)$ represent the rotation group of the cube, and $(G, \circ)$ be the face permutation group induced by $(D, *)$. Then, the cycle index of $(G, \circ)$ is
$$
P_{G}\left(x_{1}, x_{2}, \cdots, x_{6}\right)=\frac{1}{24}\left(x_{1}^{6}+8 x_{3}^{2}+6 x_{2}^{3}+3 x_{1}^{2} x_{2}^{2}+6 x_{1}^{2} x_{4}\right) \text {. }
$$

Using $m$ colors to paint the 6 faces of the cube, each face painted with one color, the resulting colored cube corresponds to a mapping from $A$ to $B$, and vice versa. Let $W_{1}$ and $W_{2}$ be two colored cubes, and the mappings corresponding to $W_{1}$ and $W_{2}$ be $f_{1}$ and $f_{2}$, respectively. Then $W_{1}$ and $W_{2}$ have the same pattern if and only if there exists a rotation $d$ of the cube such that $W_{1}$, after being rotated by $d$, becomes $W_{2}$, which is equivalent to $\forall a \in \boldsymbol{A}, f_{1}(g a)=f_{2}(a)$, where $g$ is the face permutation induced by $d$. Therefore, the number of distinct patterns $g(m)$ is equal to the number of $G$-orbits of $B^{A}$. By Corollary 7.3, the number of distinct face-colored cubes is
$$
\begin{aligned}
g(m) & =P_{G}(m, m, m, m, m, m) \\
& =\frac{1}{24}\left(m^{6}+8 m^{2}+6 m^{3}+3 m^{2} \cdot m^{2}+6 m^{2} \cdot m\right) \\
& =\frac{1}{24}\left(m^{6}+8 m^{2}+12 m^{3}+3 m^{4}\right) .
\end{aligned}
$$