Wilson's theorem Prime Generator

It is not always prime: $ f(13) = 13 \times 2834329 $. For the primes $ 2 \leq p \leq 997 $, the only time $ f(p) $ is (probably) prime is for $ p = 5, 7, 11, 29, 773 $.


That's false. First counterexample $13$.

$$\frac{(13-1)! +1}{13} = 36846277 = 13 \times 2834329$$

And if you do not like that it is $13$ that shows up again take $17$.

$$\frac{(17-1)! +1}{17} = 1230752346353 = 61\times 137\times 139 \times 1059511$$

Or also $19$ and $23$. Then for $29$ it is prime again.

A reason why it is plausible that it is true for small $n$ frequently is that $(n-1)!+1$ cannot be divisible by any primes less than $n$. But otherwise there is not much reason for this to be prime, though it should still be prime a bit more frequently than a typical number of that size.