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

The Wiki page on Twin Primes says

The pair $(m, m+2)$ is twin prime, iff $4((m-1)! + 1) \equiv -m \pmod {m(m+2)}$.

This is obviously connected to Wilson's Theorem. Can anybody provide a proof for that, along the lines of thought given here, Wilson's Theorem/Proofs/Prime modulus – another proof?

-
Use Chinese Remainder theorem. If $m$ is odd, then the right condition is equivalent to two formulas: $4((m-1)!+1) \equiv 0 \pmod m$ and $4((m-1)!+1)\equiv -2 \pmod {m+2}$. The case where $m$ is even needs to be dealt with separately. –  Thomas Andrews May 14 '12 at 19:43

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.

-
Very nice. Not along the lines I asked for, but (even better) I learnt something else. Thank you. –  draks ... May 14 '12 at 21:43

Hint $\$ Both directions can be quickly and easily proved simultaeneously using Wilson's theorem:

$\begin{eqnarray} \rm m\ prime &\iff&\rm\ mod\ m\!:\ &\rm\: 1+(m\!-\!1)! \equiv 0\iff 4(m\!-\!1)!+4\equiv 0\equiv -m \\ \rm m\!+\!2\ prime &\iff&\rm mod\ m\!+\!2\!:\ &\rm\: 1+(m\!+\!1)!\equiv 0\iff 4(m\!-\!1)!+4 \equiv 2\equiv -m\\ \rm & &\rm because &\rm \!\!\!\!2(1+(m\!+\!1)!)\:\ =\:\ 2\: +\: 4(m\!-\!1)! + 2(m\!+\!2)(m\!-\!1)(m\!-\!1)! \\ & &\rm because &\rm\!\!\!\! 2(m\!+\!1)! = 2(m\!+\!1)m(m\!-\!1)! = (4\!+\!2(m\!+\!2)(m\!\!-\!1)\!)(m\!-\!1)! \\ \end{eqnarray}$

Remark  Explicitly, by 2nd prior: $\rm\:1+(m\!+\!1)!\equiv 0\iff 4(m\!-\!1)!\equiv -2\pmod{m\!+\!2},\:$ which yields the equivalence directly above it. Note that no ingenuity is required in the second case, other than knowing to rewrite $\rm\:(m+1)!\:$ in terms of $\rm\:(m-1)!\:$ The rest is straightforward arithmetic modulo $\rm\:m+2\:$ (which I have presented it in a form most amenable to mental verification).

-