According to the Wilson theorem if p is a prime number then (p-1)!+1 is a multiple of p.
Here 41 is a prime number so 40! +1 is completely divisible by 41. This means that 40! leaves a remainder -1 when we divide it by 41 or it leaves a remainder 41-1 =40.