# Problem Link

**Author:** Abhishek Shankhadhar

**Tester:** Raju Varshney

**Editorialist:** Vaibhav Tulsyan & Raju Varshney

# Difficulty

Easy

# Pre-requisites

# Problem

Given a positive integer N, find the number of derangements of N.

# Quick Explanation

The derangements of N can be represented by !N

!N = (N - 1) * (!(N - 1) + !(N - 2))

!0 = 1

!1 = 0.

# Explanation

Formula 1:

!N = N! * \sum\limits_{i=0}^N \frac{(-1)^{i}}{i!}

Formula 2:

!N = (N - 1) * (!(N - 1) + !(N - 2))

!0 = 1

!1 = 0.

Precompute !N for all N in range [1, 10^{5}], modulo 10^9 + 7 using either formula.