Problem #114
Revenge with Derangement
Suppose that there are N persons who are numbered 1, 2, ..., N. Let there be N hats, also numbered 1, 2, ..., N. We have to find the number of ways in which no one gets the hat having same number as his/her number.
Let the number of ways to accomplish the above task be D(N) . You need to enter the value of D(N) mod P.
Take N = 49770435560715869 and P = 223092870.