## 原始题面

Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see how Tintin, a five year’s old boy, creates trouble for his parents. Tintin is a joyful boy and is always busy in doing something. But what he does is not always pleasant for his parents. He likes most to play with household things like his father’s wristwatch or his mother’s comb. After his playing he places it in some other place. Tintin is very intelligent and a boy with a very sharp memory. To make things worse for his parents, he never returns the things he has taken for playing to their original places

Think about a morning when Tintin has managed to ‘steal’ three household objects. Now, in how many ways he can place those things such that nothing is placed in their original place. Tintin does not like to give his parents that much trouble. So, he does not leave anything in a completely new place; he merely permutes the objects

### Input

There will be several test cases. Each will have a positive integer less than or equal to 800 indicating the number of things Tintin has taken for playing. Each integer will be in a line by itself. The input is terminated by a ‘-1’ (minus one) in a single line, which should not be processed

### Output

For each test case print an integer indicating in how many ways Tintin can rearrange the things he has taken

## 题意简述

$$n$$ 个元素的错排数

## 解题思路

$$D(n)$$$$n$$ 个元素的错排数，则

$D(n)=\begin{cases} 0,&n=1\\ 1,&n=2\\ (n-1)(D(n-1)+D(n-2)),&n>2 \end{cases}$

Show code