8.040. $\operatorname{ctg}\left(\frac{3 \pi}{2}-x\right)-\operatorname{ctg}^{2} x+\frac{1+\cos 2 x}{\sin ^{2} x}=0$.
Solution.

Domain of definition: $\left\{\begin{array}{l}\cos x \neq 0, \\ \sin x \neq 0 .\end{array}\right.$

Rewrite the given equation as

$$
\begin{aligned}
& \operatorname{tg} x-\operatorname{ctg}^{2} x+\frac{1+2 \cos ^{2} x-1}{\sin ^{2} x}=0, \Leftrightarrow \operatorname{tg} x-\operatorname{ctg}^{2} x+2 \operatorname{ctg}^{2} x=0, \\
& \operatorname{ctg}^{2} x+\frac{1}{\operatorname{ctg} x}=0, \operatorname{ctg}^{3} x=-1, \operatorname{ctg} x=-1
\end{aligned}
$$

Then $x=\frac{3}{4} \pi+\pi k=\frac{\pi}{4}(4 k+3), k \in Z$.

Answer: $\quad x=\frac{\pi}{4}(4 k+3), \quad k \in Z$.