Residue of $\sum^{22}_{i=1} i!$ divided by $23$ I was working in a problem and found that I need to calculate this residue.
I know Wilson Theorem so the residue of the last term is -1, that cancels with the first. So then I just calculate this in my PC, or is an analytic way to solve this.
 A: there seem to be some interesting patterns; could be a closed form answer, hard to say. I suppose a responsible person would do the same type of table for smaller primes. Perhaps it always gives $p-3,$ who knows?
23: 
   1       1       1
   2       2       3
   3       6       9
   4       1      10
   5       5      15
   6       7      22
   7       3       2
   8       1       3
   9       9      12
  10      21      10
  11       1      11
  12      12       0
  13      18      18
  14      22      17
  15       8       2
  16      13      15
  17      14       6
  18      22       5
  19       4       9
  20      11      20
  21       1      21
  22      22      20

well, no;
  prime  19
       1       1       1
       2       2       3
       3       6       9
       4       5      14
       5       6       1
       6      17      18
       7       5       4
       8       2       6
       9      18       5
      10       9      14
      11       4      18
      12      10       9
      13      16       6
      14      15       2
      15      16      18
      16       9       8
      17       1       9
      18      18       8

A: You can calculate the sum by nesting: $1+2(1+3(1+4(1+\cdots)))$. This Python code computes 
$$f(p) = \sum_{i=1}^{p-1} i! \bmod p$$
pretty quickly:
def f(p):
    ans = p-1
    for n in range(p-2,0,-1):
        ans = (1 + ans) * n % p
    return ans

