# Find the next "Wilson-like" prime

For odd primes $p$, the congruence $$(-1)^{\frac{p-1}{2}}+(\frac{p-1}{2}!)^2 \equiv 0 \mod p$$ is shown here.

Like for Wilson congruence, it seems to hold$\mod p^2$, but for a restricted list of primes: $$3,11,31,47,53,...?$$

Find the next one. (if any, it seems to be quite far away)

• Not sure looking at $(p-1)! \bmod p^2$ would help, but any idea on this ? Commented Oct 1, 2016 at 20:49
• Ever any luck on this? Commented Apr 15, 2017 at 7:15

The fact that this congruence holds in general modulo p was show by Lagrange in “Démonstration d’un théoreme nouveau concernant les nombres premiers,” Nouveaux Mémoires de l’Academie Royale des Sciences et Belles-Lettres [de Berlin], année 1771 (published 1783), 125–137, at pp. 131–32.

G. B. Mathews, Theory of Numbers, part 1 [all published] (Cambridge, 1892), p. 318, a reference kindly brought to my attention several years ago by David Harvey, contains a congruence for the factorial expression that allows us to deduce that Lagrange's congruence holds modulo $p^2$ iff

$$(p - 1)! \equiv -4^{p - 1} \pmod{p^2};$$

in other words, adding 1 to both sides, dividing throughout by $p$, and applying Eisenstein’s logarithmetic rule for the Fermat quotient,

$$W_p \equiv -2 q_{p}(2) \pmod{p},$$

where $W_p$ is the Wilson quotient of $p$ and $q_p(2)$ is the Fermat quotient of $p$, base 2. This expression may also be obtained using the better-known theorem of Morley [Annals of Mathematics, 9 (1894–1895), 168–170], but the full force of Morley’s theorem is not really needed here.

So if this does not exactly simplify the original problem, it at least moves it into more familiar territory. And although it probably does not make the problem any easier, it may also be noted that using a congruence by J. W. L. Glaisher, “On the residues of the sums of products of the first p − 1 numbers, and their powers, to modulus p2 or p3,” Quarterly Journal of Mathematics, 31 (1899–1900), 321–353, the congruence modulo $p^2$ above could be rewritten as a condition involving a Bernoulli number (in the usual even-index notation):

$$p(B_{p - 1} - 1) \equiv -4^{p - 1} \pmod{p^2}.$$

ADDENDUM (16 December 2017): M. Lerch, “Zur Theorie des Fermatschen Quotienten $\frac{a^{p-1}-1}{p} = q(a)$,” Mathematische Annalen 60 (1905), 471–490, showed that

$$W_p \equiv \sum_{a=1}^{p-1} q_p(a) \pmod{p}.$$

Comparing this with the criterion $W_p \equiv -2 q_{p}(2) \bmod{p}$ above, the condition for the primes in the original post can be written

$$\sum_{a=1}^{p-1} q_p(a) + 2q_p(2) \equiv 0 \pmod{p}.$$

With an application of the reverse of Eisenstein’s rule, this simplifies to

$$q_p(4(p-1)!) \equiv 0 \pmod{p}.$$

This expression is of course more cumbersome than the original one from a computational standpoint, but from a purely formal point of view it may have some interest as a condition that can be expressed, modulo $p$, as a single function of $p$.

• As to the mod $p$ congruence above, if we can assume that $W_p$ and $q_p(2)$ are independent modulo $p$, then the probability that the congruence is satisfied is $\frac{1}{p}$. If that is true, then the number of solutions less than a limit $n$ would be $\sum_{primes < n} \frac{1}{p}$, which is asymptotic to $loglog(n + 1)$, as noted in "Divergence of the sum of the reciprocals of the primes" at link. Thus, we would expect the solutions to grow hyperexponentially. Commented Jul 18, 2017 at 3:19