<s>[INST] Trigonometric equation with parameter 
Find $p$ for which $\cos^2(x) - \cos(x) + p + 1 = 0$ has EXACTLY two solutions for $0 \le x \le 2\pi$

I tried to substitute $t = \cos(x)$ and then I got two solutions, but I don't know what to do next. 
$t_1 = \frac{1 + \sqrt{-3 - 4p}}{2}$
$t_2 = \frac{1 - \sqrt{-3 - 4p}}{2}$
 [/INST] Since $\cos x=T$ has at most two real solutions in $0\le x\le 2\pi$ for a given real constant $T$, we have three cases.
(1) $\cos x=t_1$ has no solution and $\cos x=t_2$ has two solutions.
(2) $\cos x=t_1$ has exactly one solution and $\cos x=t_2$ has exactly one solution.
(3) $\cos x=t_1$ has two solutions and $\cos x=t_2$ has no solution.
Note here that 


*

*$\cos x=T$ has no solution in $0\le x\le 2\pi$ if and only if $|T|\gt 1$. 

*$\cos x=T$ has exactly one solution in $0\le x\le 2\pi$ if and only if $T=-1$. 

*$\cos x=T$ has two solutions in $0\le x\le 2\pi$ if and only if $-1\lt T\le 1$.
So, noting that (2) does not occur, the answer is
$$\{p\mid -3-4p=0\}\cup \left\{p\mid -3-4p\gt 0,\frac{1+\sqrt{-3-4p}}{2}\gt 1,-1\lt\frac{1-\sqrt{-3-4p}}{2}\le 1\right\}\cup \left\{p\mid -3-4p\gt 0,-1\lt \frac{1+\sqrt{-3-4p}}{2}\le 1,\frac{1-\sqrt{-3-4p}}{2}\lt -1\right\},$$
i.e.
$$\color{red}{p=-\frac 34\quad\text{or}\quad -3\lt p\lt -1}.$$
</s>