Proving $\cos^{2}\frac{\pi}{2n} \cos^{2}\frac{3\pi}{2n}\cdots \cos^{2}\frac{\left(n-2\right)\pi}{2n}=n2^{1-n}$ using complex numbers Using $$z^{2n}+1 = \prod_{k=1}^{n}\left(z^2-2z\cos{\left(\frac{\left(2k-1\right)\pi}{2n}\right)}+1\right)$$
and $$z^{2n}+1 = \left(1+z^2\right)\left(1-z^2+z^4-\cdots+z^{2n-2}\right)$$
prove, for $n$ odd, $$\cos^{2}{\left(\frac{\pi}{2n}\right)} \cos^{2}{\left(\frac{3\pi}{2n}\right)} \cos^{2}{\left(\frac{5\pi}{2n}\right)} \cdots \cos^{2}{\left(\frac{\left(n-2\right)\pi}{2n}\right)} = n2^{1-n}$$
The provided solution (from the original source of this problem) involves noting that in the first result, the product will contain a factor of $\left(1+z^2\right)$, where $k=\frac{n+1}{2}$ (which is an integer since $n$ is odd). Thus, substituting in the second result, they cancel the factor of $\left(1+z^2\right)$ on both sides, and then set $z=i$ to deduce the required result.

But my question is, since $z=i$ gives $1+z^2=0$, are we allowed to make this cancellation and then still set $z=i$, since we seem to be dividing by zero? If there is in fact a problem, can their proof be easily repaired?

 A: There is no problem; you can view the identity as an equality of polynomials in $\Bbb{C}[z]$. This is an integral domain, meaning that you can cancel non-zero factors; the factor $1+z^2$ is a non-zero polynomial, so you can cancel it. 
This gives you a simpler equality of polynomials. You can then evaluate these two polynomials in $z=i$ to obtain the given identity.

More formally; combining the given expressions for $z^{2n}+1$ shows that
\begin{eqnarray*}
0&=&\left(1+z^2\right)\left(1-z^2+z^4-\cdots+z^{2n-2}\right)
-\prod_{k=1}^{n}\left(z^2-2z\cos{\left(\frac{\left(2k-1\right)\pi}{2n}\right)}+1\right)\\
&=&(1+z^2)\left(1-z^2+z^4-\cdots+z^{2n-2}
-\prod_{k=1}^{n-1}\left(z^2-2z\cos{\left(\frac{\left(2k-1\right)\pi}{2n}\right)}+1\right)\right),\\
\end{eqnarray*}
as polynomials. This means one of the two factors is the zero polynomial. Clearly this is not $1+z^2$, so
$$1-z^2+z^4-\cdots+z^{2n-2}
-\prod_{k=1}^{n-1}\left(z^2-2z\cos{\left(\frac{\left(2k-1\right)\pi}{2n}\right)}+1\right)=0,$$
which shows that indeed
$$1-z^2+z^4-\cdots+z^{2n-2}
=\prod_{k=1}^{n-1}\left(z^2-2z\cos{\left(\frac{\left(2k-1\right)\pi}{2n}\right)}+1\right).$$
Now plugging in $z=i$ yields the desired identity.
