Wilson's Theorem states (for $p>1$)
$$p\;\text{is prime} \quad\iff\quad(p-1)! = -1 \bmod p$$
I was asked the following:
Explain the difference in reducing modulo $p$ after each multiplication needed to find $(p–1)!$ or reducing modulo $p$ once after end of calculations of $(p–1)!$.
But I don't understand what that means.
Say we want to find if $5$ and if $8$ are primes. Here is how I would do it:
$p = 5$ $$(5-1)! = 4! = 24$$ $$24 \bmod 5 = -1 \bmod 5$$ Thus, $5$ is prime.
$p = 8$ $$(8-1)! = 7! = 5040$$ $$5040 \bmod 8 = 0 \neq -1 \bmod 8$$ Thus, $8$ is not prime.
How does this relate to reductions?
Thank you.