Claim: For any prime p: (p-1)! = -1 (mod p)Proof: For p=2: 1! = 1 so the equality obviously holds. Therefore, we need to consider cases when p is odd.
Let's consider set: {1, ... , p-1}. With operation * multiplication, this set clearly forms a group. The neutral element is 1. The cardinality of this group is p-1. For now, let's forget about first and last element (which are congruent 1 and -1 to p). Therefore we are left with p-3 (so even) number of elements and we know that for each e in this subset, there exists also its inverse within this subset. This is true, because we know that inverse of 1 is 1, inverse of p-1 is p-1 and there is only 1 inverse for each e, so they must be inside our subset. Therefore product of all numbers in subset is:12...(p-2) = 1 * ... * 1 = 1Finally we need to multiply this result by 1 and by (p-1) to obtain (p-1)! mod p. But (p-1)=-1 mod p, so our final result is 11*(-1) = -1 mod p, which was to be demonstrated.