$(m, m+2)$ is twin prime, iff $4((m-1)! + 1) \equiv -m \pmod {m(m+2)}$ [closed]

Solution 1:

By Wilson's Theorem, if $m$ is prime, then $(m-1)!+1\equiv 0\pmod{m}$, and therefore $$4[(m-1)!+1]+m \equiv 0\pmod{m}.\tag{$1$}$$

If $m+2$ is prime, then $(m+1)!+1\equiv 0\pmod{m+2}$, again by Wilson's Theorem. But since $m+1\equiv -1\pmod{m+2}$, and $m\equiv -2\pmod{m+2}$, we have $(m+1)!\equiv (-1)(-2)(m-1)!\equiv 2(m-1)!\pmod{m+2}$, and therefore $$4[(m-1)!+1]+m \equiv 2(m+1)!+2+m+2\equiv 0\pmod{m+2}.\tag{$2$}$$ Since $m$ is odd, the numbers $m$ and $m+2$ are relatively prime, and therefore by $(1)$ and $(2)$ we have $4[(m-1)!+1]+m\equiv 0\pmod{m(m+2)}$.

The proof of the converse follows similar lines, this time using the fact that the Wilson condition is sufficient for primality.

Solution 2:

Hint $ $ Both directions can be quickly and easily proved simultaneously by Wilson's theorem: $\ \ \begin{eqnarray} \rm m\ prime &\iff&\rm\ mod\ m\!:\ &\rm\: 1+(m\!-\!1)! \equiv 0\!\!\overset{\times\,4\!\!}\iff 4(m\!-\!1)!+4\equiv 0\equiv -m \\[-.0em] \rm m\!+\!2\ prime &\iff&\rm mod\ m\!+\!2\!:\ &\rm\: 1+(m\!+\!1)!\equiv 0\!\!\overset{\times\,\color{#c00}2\!}\iff 4(\color{#90f}{m\!-\!1})!+\color{#c00}4 \equiv \color{#c00}2\equiv -m\\[.4em] \rm & &\rm \ \ \ \ \ \ \ \ \ \ \ \ \, by &\rm \!\!\!\!\color{#c00}2\:\!(1+\!\!\!\underbrace{(m\!+\!1)!}_{\!\!\!\!\underbrace{\color{#0a0}{(m+1)m}}_{\large \color{#0a0}{(-1)\,(-2)}}\color{#90f}{(m-1)!}}\!\!\!)\:\ \ \equiv\ \ \ \ \,\color{#c00}2\:\!\color{#0a0}{(2)}\color{#c00}{\color{#90f}{(m\!-\!1)!}} + \color{#c00}2 \\[.2em] \end{eqnarray}$