# subfactorial function

Subfactorial: how many ways to reorder n items so none stays in place.

## How to write it

### subfactorial(n)

**n**

A whole number. Takes a whole number.

## Examples

- $\displaystyle \operatorname{subfactorial}(4) = 9$

  `subfactorial(4)`

  In the solver, `subfactorial(4)` gives `9`.

  [Open in the solver](https://hilberon.com/?q=subfactorial%284%29)

## Related functions

- [totient](https://hilberon.com/library/totient)

  Euler's totient: how many whole numbers up to n are coprime to n.
- [stirling_s2](https://hilberon.com/library/stirling_s2)

  Stirling number of the second kind: the ways to split n items into k groups.
- [bell_b](https://hilberon.com/library/bell_b)

  The n-th Bell number: how many ways to split n items into groups.
- [stirling_s1](https://hilberon.com/library/stirling_s1)

  Stirling number of the first kind, with sign.
- [bernoulli_b](https://hilberon.com/library/bernoulli_b)

  The n-th Bernoulli number.
- [squares_r](https://hilberon.com/library/squares_r)

  How many ways a whole number is a sum of a given count of squares, counting order and signs.

---
Source: https://hilberon.com/library/subfactorial
