In the case of 10, 10=3628800, everyone takes a hat at random, and only two people get the correct hat. Then in the case of 10, two hats are C 10 and 2 = 45, and the other eight people don't take their own hats. Number the remaining eight people and the corresponding eight hats. Let the number 1 take it first, then let the number 1 take another hat, and so on. Eight people wear (7 * 5 * 3) 2 = 1 1025 kinds of hats. So the probability is 45 *11025/3628800 = 245/1792.
Welcome to adopt, remember to comment!