Prove that the function $F(j) = \left\lfloor\cos\left(\pi\dfrac{(j-1)!+1}{j}\right)\right\rfloor$ returns $-1$ when $j$ is prime and $0$ when $j$ is composite.
First note that $$\cos(n\pi) =\left\{\begin{aligned}-1&, \quad \text{if} \text{ } n \text{ } \text{is odd}\\ 1&, \quad\text{if} \text{ } n \text{ } \text{is even}.\end{aligned}\right.$$ We have $F(2) = -1$. Now if $j > 2$ is prime, then by Wilson's Theorem $(j-1)!+1 \equiv 0 \pmod{j}$. Thus, since $j$ is odd and $(j-1)!+1$ is also odd, it follows that $\dfrac{(j-1)!+1}{j}$ is an odd integer and so $F(j) = -1$.
How do I solve it when $j$ is composite?