# Solving for the smallest $x$ : $1! + 2! + \cdots+ 20! \equiv x\pmod 7$

I know the smallest $x \in \mathbb{N}$, satisfying $1! + 2! + \cdots + 20! \equiv x\pmod7$ is $5$. I would like to know methods to get to the answer.

-
One natural question, I think, is to find the remainder when $1! + 2! + \cdots + (n-1)!$ is divided by $n$. This is oeis.org/A067462 . The problem of when this is zero is apparently of at least minor interest, according to Guy, Unsolved Problems in Number Theory: oeis.org/A057245 – Michael Lugo Dec 14 '11 at 1:49

Note that each of $7!$, $8!$, $9!,\ldots, 20!$ is congruent to $0$ modulo $7$, since they are all divisible by $7$.
Note that $6!\equiv -1\pmod{7}$ by Wilson's Theorem, which cancels $1!$.
That leaves $2!+3!+4!+5! = 2! + 3!(1 + 4 + 20)$. But $3!\equiv -1\pmod{7}$, and $20\equiv -1\pmod{7}$, so $2!+3!+4!+5! \equiv 2-(1+4-1) = -2\equiv 5\pmod{7}$.
It is implicit in Arturo's answer, but it is interesting to note that $1! + 2! + \cdots + n! \equiv 5$ for any $n \geq 7$. – Austin Mohr Dec 13 '11 at 22:11