You move the exponent inside the cosine.
The theorem applies to the whole bracket $(\cos\theta + i\sin\theta)^n$, never to $\cos^n\theta$. For $z^n = w$, write the argument as $\theta + 2k\pi$ before dividing.
Next time: Write the $+2k\pi$ before you divide the argument.