This site is supported by donations to The OEIS Foundation.

# Factorial

The factorial of a nonnegative integer ${\displaystyle \scriptstyle n}$ is defined as the product of all positive integers up to ${\displaystyle \scriptstyle n}$, and is notated as ${\displaystyle \scriptstyle n!}$. For example, 7! = 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040. The factorial of 0 is defined as the empty product, 1. Factorials comes after parenthesized expressions but before exponentiation in the order of operator precedence.

A000142 The factorial numbers ${\displaystyle \scriptstyle n!,\ n\,\geq \,0}$.

{1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, ...}

${\displaystyle n!}$ is the smallest number with that prime signature. E.g., 720 = 2 4 × 3 2 × 5.

Conjecturally, 1, 6, and 120 are the only numbers which are both triangular and factorial.

## Applications of factorials

Factorials have applications in many branches of mathematics.

In regards to matrices:

• For ${\displaystyle n>0}$, ${\displaystyle a(n)}$ is the number of n X n (0,1) matrices with each row and column containing exactly one entry equal to 1.
• a(n) is the permanent of the n X n matrix M with M(i, j) = 1.
• a(n) is also the determinant of an square matrix, An, whose coefficients are the reciprocals of beta function: a{i, j} = 1/beta(i, j), det(An) = n!

In regards to graphs:

• n! is also the number of optimal broadcast schemes in the complete graph ${\displaystyle K_{n}}$, equivalent to the number of binomial trees embedded in ${\displaystyle K_{n}}$.[1]
• Let ${\displaystyle S_{n}}$ denote the n-star graph. The ${\displaystyle S_{n}}$ structure consists of ${\displaystyle n}$ ${\displaystyle S_{n-1}}$ structures. This sequence gives the number of edges between the vertices of any two specified ${\displaystyle S_{n+1}}$ structures in ${\displaystyle S_{n+2}}$, with ${\displaystyle n>0}$).
• Chromatic invariant of the sun graph ${\displaystyle S_{n-2}}$.

In regards to chains:

• The number of chains of maximal length in the power set of {1, 2, ..., n} ordered by the subset relation.
• a(n) is also the number of order-decreasing full transformations (of an n-chain).
• a(n - 1) is also the number of nilpotent order-decreasing full transformations (of an n-chain).

In regards to permutations:

• The number of circular permutations of n letters for n >= 0 is 1, 1, 1, 2, 6, 24, 120, 720, 5040, 40320, ...
• Consider the n! permutations of the integer sequence [n] = 1, 2, ..., n. The i-th permutation consists of ncycle(i) permutation cycles. Then, if the sum Sum_{i = 1}^{n!} 2^ncycle(i) runs from 1 to n!, we have ${\displaystyle \sum _{i=1}^{n!}2^{ncycle(i)}=(n+1)!}$. E.g., for n = 3 we have ncycle(1) = 3, ncycle(2) = 2, ncycle(3) = 1, ncycle(4) = 2, ncycle(5) = 1, ncycle(6) = 2 and 2^3 + 2^2 + 2^1 + 2^2 + 2^1 + 2^2 = 8 + 4 + 2 + 4 + 2 + 4 = 24 = (n+1)!.
• Number of permutations of elements 1, 2, ..., n + 1 with a fixed element belonging to a cycle of length r does not depend on r and equals a(n).
• a(n) is the number of fixed points in all permutations of 1, ..., n: in all n! permutations, 1 is first exactly (n - 1)! times, 2 is second exactly (n - 1)! times, etc., giving (n - 1)!n = n!.

In regards to partitions:

• a(n) is the number of partition tableaux of size n. See Steingrimsson/Williams link for the definition.
• a(n) is the number of set partitions of {1, 2, ..., 2n - 1, 2n} into blocks of size 2 (perfect matchings) in which each block consists of one even and one odd integer. For example, a(3) = 6 counts 12-34-56, 12-36-45, 14-23-56, 14-25-36, 16-23-45, 16-25-34.

Number of distinct subsets of T(n-1) elements with 1 element A, 2 elements B,..., n - 1 elements X (e.g., at n = 5, we consider the distinct subsets of ABBCCCDDDD and there are 5! = 120).

Given n objects of distinct sizes (e.g., areas, volumes) such that each object is sufficiently large to simultaneously contain all previous objects, then n! is the total number of essentially different arrangements using all n objects. Arbitrary levels of nesting of objects are permitted within arrangements. (This application of the sequence was inspired by considering leftover moving boxes.) If the restriction exists that each object is able or permitted to contain at most one smaller (but possibly nested) object at a time, the resulting sequence begins 1,2,5,15,52 (Bell Numbers?). Sets of nested wooden boxes or traditional nested Russian dolls come to mind here.2004

n! is the n-th finite difference of consecutive n-th powers. E.g. for n = 3, [0, 1, 8, 27, 64, ...] -> [1, 7, 19, 37, ...] -> [6, 12, 18, ...] -> [6, 6, ...]

Write numbers 1 to n on a circle. Then a(n) = sum of the products of all n - 2 adjacent numbers. E.g., a(5) = 1*2*3 + 2*3*4 + 3*4*5 + 4*5*1 +5*1*2 = 120.

Consider the multiset M = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, ...] = [1, 2, 2, ..., n x 'n'] and form the set U (where U is a set in the strict sense) of all subsets N (where N may be a multiset again) of M. Then the number of elements |U| of U is equal to (n+1)!. E.g. for M = [1, 2, 2] we get U = [[], [2], [2, 2], [1], [1, 2], [1, 2, 2]] and |U| = 3! = 6.

Increasing colored 1-2 trees with choice of two colors for the rightmost branch of nonleaves.

Number of necklaces with n labeled beads of 1 color.

## Formulae

${\displaystyle n!:=\prod _{k=1}^{n}k=1^{(n)}=n_{(n)},}$

where ${\displaystyle \scriptstyle x^{(n)}}$ and ${\displaystyle \scriptstyle x_{(n)}}$ are respectively the rising factorial and the falling factorial.

${\displaystyle (2n)!=2^{n}\prod _{k=1}^{n}t_{2k-1}=2^{n}\prod _{k=1}^{n}k(2k-1)=2^{n}~n!\prod _{k=1}^{n}(2k-1)=2^{n}~n!~(2n-1)!!,\quad n\geq 0,}$
${\displaystyle (2n+1)!=(2n+1)(2n)!=(2n+1)~2^{n}\prod _{k=1}^{n}t_{2k-1}=(2n+1)~2^{n}\prod _{k=1}^{n}k(2k-1)=2^{n}~n!\prod _{k=1}^{n+1}(2k-1)=2^{n}~n!~(2n+1)!!,\quad n\geq 0,}$

where ${\displaystyle \scriptstyle t_{n}}$ is the ${\displaystyle \scriptstyle n}$ th triangular number, ${\displaystyle \scriptstyle n!!}$ is the double factorial and where for ${\displaystyle \scriptstyle 0!}$ we get the empty product 1.

The following definite integral (Euler's integral form) for the factorial

${\displaystyle n!=\int _{0}^{\infty }x^{n}e^{-x}dx}$

leads to the generalization for ${\displaystyle \scriptstyle \Re (z)\,>\,0}$

${\displaystyle \Gamma (z)=\int _{0}^{\infty }t^{z-1}e^{-t}dt}$

which is called the gamma function.

For ${\displaystyle \scriptstyle z\,=\,n}$ a nonnegative integer, we thus have

${\displaystyle \Gamma (n)=(n-1)!}$

a result of the somewhat unfortunate notation due to Legendre.[2]

## Recurrences

${\displaystyle n!={\begin{cases}1&{\text{if }}n=0,\\n\cdot (n-1)!&{\text{if }}n>0.\end{cases}}}$
${\displaystyle n!=(n-1)\cdot [(n-1)!+(n-2)!],\,n\,\geq \,2.}$

Note that the subfactorial has a similar recurrence

${\displaystyle !n=(n-1)\cdot [!(n-1)+!(n-2)],\,n\,\geq \,2.}$

So, for ${\displaystyle \scriptstyle n\,\geq \,2,}$

${\displaystyle {\frac {n!}{(n-1)!+(n-2)!}}=n-1={\frac {!n}{!(n-1)+!(n-2)}}.}$

## Generating function

${\displaystyle G_{\{n!\}}(x)=\sum _{n=0}^{\infty }n!~x^{n}=?}$

## Exponential generating function

The exponential generating function of ${\displaystyle \scriptstyle n!}$ is

${\displaystyle E_{\{n!\}}(x)=\sum _{n=0}^{\infty }n!~{\frac {x^{n}}{n!}}=\sum _{n=0}^{\infty }x^{n}={\frac {1}{1-x}}.}$

## Asymptotic behavior

${\displaystyle n!\sim {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$

## Approximations to ${\displaystyle n!}$

Approximations to ${\displaystyle n!}$ (With ${\displaystyle \scriptstyle [n]}$ as the nearest integer function.)
${\displaystyle n}$ Factorial

A000142
${\displaystyle n!}$

Stirling's approximation

(nearest integer)
A005394
${\displaystyle {\bigg [}{\sqrt {2n\pi }}\left({\frac {n}{e}}\right)^{n}{\bigg ]}}$

${\displaystyle {\bigg [}{\sqrt {2n\pi }}\left({\frac {n}{e}}\right)^{n}{\bigg ]}-n!}$

Gosper's approximation

(nearest integer)
A090583
${\displaystyle {\bigg [}{\sqrt {(2n+{\tfrac {1}{3}})\pi }}\left({\frac {n}{e}}\right)^{n}{\bigg ]}}$

${\displaystyle {\bigg [}{\sqrt {(2n+{\tfrac {1}{3}})\pi }}\left({\frac {n}{e}}\right)^{n}{\bigg ]}-n!}$

0 1 0
–1
1
0
1 1 1
0
1
0
2 2 2
0
2
0
3 6 6
0
6
0
4 24 24
0
24
0
5 120 118
–2
120
0
6 720 710
–10
720
0
7 5040 4980
–60
5039
–1
8 40320 39902
–418
40316
–4
9 362880 359537
–3343
362851
–29
10 3628800 3598696
–30104
3628561
–239
11 39916800 39615625
–301175
39914615
–2185
12 479001600 475687486
–3314114
478979481
–22119
13 6227020800 6187239475
–39781325
6226774954
–245846
14 87178291200 86661001741
–517289459
87175314872
–2976328
15 1307674368000 1300430722199
–7243645801
1307635379670
–38988330
16 20922789888000 20814114415223
?
20922240412500
?
17 355687428096000 353948328666101
?
355679137660826
?
18 6402373705728000 6372804626194309
?
6402240370021199
?
19 121645100408832000 121112786592293963
?
121642823201649058
?
20 2432902008176640000 2422786846761133394
?
2432860847996122437
?
21 51090942171709440000  ?
?
51090157192742729183
?
22 1124000727777607680000  ?
?
1123984974735953018069
?
23 25852016738884976640000  ?
?
25851684898376695192336
?
24 620448401733239439360000  ?
?
620441080509682809701382
?
25 15511210043330985984000000  ?
?
15511041215936944579902093
?
26 403291461126605635584000000  ?
?
403287399526697316252516250
?
27 10888869450418352160768000000  ?
?
10888767684658777169852805388
?
28 304888344611713860501504000000  ?
?
304885693246011383041733210739
?
29 8841761993739701954543616000000  ?
?
8841690269587826737517642605696
?
30 265252859812191058636308480000000  ?
?
265250847945328962838481886897160
?

### Stirling's approximation to ${\displaystyle n!}$

Stirling's approximation to ${\displaystyle n!}$ is

${\displaystyle n!\approx {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}.}$

A005395 Leading term of Stirling's approximation to n!, sqrt(2*Pi)*n^(n+(1/2))/e^n, rounded up.

{0, 1, 2, 6, 24, 119, 711, 4981, 39903, 359537, 3598696, 39615626, 475687488, 6187239487, 86661001990, 1300430725000, 20814114480000, 353948329800000, 6372804643000000, 121112787000000000, ...}

A005394 Leading term of Stirling's approximation to n!, sqrt(2*Pi)*n^(n+(1/2))/e^n, n ≥ 0, rounded to nearest integer.

{0, 1, 2, 6, 24, 118, 710, 4980, 39902, 359537, 3598696, 39615625, 475687486, 6187239475, 86661001741, 1300430722199, 20814114415223, 353948328666101, 6372804626194309, 121112786592293963, 2422786846761133394, ...}

A005393 Leading term of Stirling's approximation to n!, sqrt(2*Pi)*n^(n+(1/2))/e^n, rounded down.

{0, 0, 1, 5, 23, 118, 710, 4980, 39902, 359536, 3598695, 39615625, 475687487, 6187239487, 86661001990, 1300430725000, 20814114480000, 353948329800000, 6372804643000000, 121112787000000000, ...}

### Gosper's approximation to ${\displaystyle n!}$

R. W. Gosper's approximation to ${\displaystyle n!}$ is

${\displaystyle n!\approx {\sqrt {(2n+{\tfrac {1}{3}})\pi }}\left({\frac {n}{e}}\right)^{n}.}$

A090583 Gosper's approximation to n!, sqrt((2*n+1/3)*pi)*n^n/e^n, n ≥ 0, rounded to nearest integer.

{1, 1, 2, 6, 24, 120, 720, 5039, 40316, 362851, 3628561, 39914615, 478979481, 6226774954, 87175314872, 1307635379670, 20922240412500, 355679137660826, 6402240370021199, 121642823201649058, 2432860847996122437, ...}

There are other approximations, see the work of Luschny Other Approx

## Sum of reciprocals of ${\displaystyle n!}$

${\displaystyle \sum _{n=0}^{\infty }{\frac {1}{n!}}=e,{\rm {~and~}}\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{n!}}={\frac {1}{e}},}$

where e is the base of the natural logarithm.

These are obtained from the Maclaurin expansion of ${\displaystyle \scriptstyle e^{x}}$ evaluated at ${\displaystyle \scriptstyle x\,=\,1}$ and ${\displaystyle \scriptstyle x\,=\,-1}$

${\displaystyle \sum _{n=0}^{\infty }{\frac {x^{n}}{n!}}=e^{x}}$

## Prime factors of ${\displaystyle n!}$

The number of prime factors (with multiplicity) of ${\displaystyle \scriptstyle n!}$ is given by the summatory Omega function

${\displaystyle \Omega (n!)=\sum _{i=1}^{n}\Omega (i).}$

The number of distinct prime factors of ${\displaystyle \scriptstyle n!}$ is given by the prime counting function ${\displaystyle \scriptstyle \pi (n)}$

${\displaystyle \omega (n!)=\omega ({\rm {rad}}(n!))=\omega (n\#)=\pi (n),}$

where ${\displaystyle \scriptstyle {\rm {rad}}(n!)}$ is the radical of ${\displaystyle \scriptstyle n!}$, i.e. the squarefree kernel ${\displaystyle \scriptstyle {\rm {sqf}}(n!)}$.

The sum of prime factors (with multiplicity) (integer log) of ${\displaystyle \scriptstyle n!}$ is

${\displaystyle {\rm {sopfr}}(n!)=\ ?}$

The sum of distinct prime factors of ${\displaystyle \scriptstyle n!}$ is the sum of prime factors of the primorial of ${\displaystyle \scriptstyle n}$

${\displaystyle {\rm {sopf}}(n!)={\rm {sopf}}(n\#)=\sum _{i=1}^{\pi (n)}p_{i},}$

where ${\displaystyle \scriptstyle \pi (n)}$ is the prime counting function and ${\displaystyle \scriptstyle p_{i}}$ is the ${\displaystyle \scriptstyle i}$-th prime.

The product of distinct prime factors (radical or squarefree kernel) of ${\displaystyle \scriptstyle n!}$ is the primorial of ${\displaystyle \scriptstyle n}$

${\displaystyle {\rm {rad}}(n!)={\rm {sqf}}(n!)=n\#=\prod _{i=1}^{\pi (n)}p_{i},}$

where ${\displaystyle \scriptstyle \pi (n)}$ is the prime counting function and ${\displaystyle \scriptstyle p_{i}}$ is the ${\displaystyle \scriptstyle i}$-th prime.

## Base 10 representation of ${\displaystyle n!}$

### Number of trailing zeros of ${\displaystyle n!}$

The number of trailing zeros (in base 10) in ${\displaystyle \scriptstyle n!}$ (highest power of 5 dividing ${\displaystyle \scriptstyle n!}$ and highest power of 10 dividing ${\displaystyle \scriptstyle n!}$) is given by

${\displaystyle {\rm {NTZ}}(n!)=\alpha (n,5)}$

where the exponent of prime ${\displaystyle \scriptstyle p}$ in the prime factorization of ${\displaystyle \scriptstyle n!}$ is given by Legendre's formula

${\displaystyle \alpha (n,p)=\sum _{k=1}^{\lfloor \log _{p}(n)\rfloor }{{\bigg \lfloor }{\frac {n}{p^{k}}}{\bigg \rfloor }}}$

## Pochhammer symbol

Depending on the context the Pochhammer symbol ${\displaystyle \scriptstyle (x)_{n}}$, introduced by Leo August Pochhammer, may represent either the rising factorial or the falling factorial as defined below.

## Falling factorial

The falling factorial (represented with ${\displaystyle \scriptstyle x_{(n)}}$) of the real number ${\displaystyle \scriptstyle x}$, ${\displaystyle \scriptstyle n}$ being a nonnegative integer is defined as

${\displaystyle x_{(n)}:=\prod _{i=0}^{n-1}(x-i),\quad n\geq 0,}$

where for ${\displaystyle \scriptstyle n\,=\,0}$ we get the empty product, giving 1.

## Rising factorial

The rising factorial (represented with ${\displaystyle \scriptstyle x^{(n)}}$) of the real number ${\displaystyle \scriptstyle x}$, ${\displaystyle \scriptstyle n}$ being a nonnegative integer is defined as

${\displaystyle x^{(n)}:=\prod _{i=0}^{n-1}(x+i),\quad n\geq 0,}$

where for ${\displaystyle \scriptstyle n\,=\,0}$ we get the empty product, giving 1.

## Sequences

The number of trailing zeros (in base 10) in ${\displaystyle \scriptstyle n!}$ (highest power of 5 dividing ${\displaystyle \scriptstyle n!}$ and highest power of 10 dividing ${\displaystyle \scriptstyle n!}$) (see A027868) are

{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, ...}

Omitting trailing zeros (in base 10) from factorial numbers, i.e. ${\displaystyle \scriptstyle {\frac {n!}{10^{\alpha (n,5)}}},\ n\,\geq \,0}$. (see A004154) gives

{1, 1, 2, 6, 24, 12, 72, 504, 4032, 36288, 36288, 399168, 4790016, 62270208, 871782912, 1307674368, 20922789888, 355687428096, 6402373705728, 121645100408832, 243290200817664, ...}

2. One would have preferred the gamma function to be defined as ${\displaystyle \scriptstyle \Gamma (z)\,=\,\int _{0}^{\infty }t^{z}e^{-t}dt}$ so as to get ${\displaystyle \scriptstyle \Gamma (n)\,=\,n!}$ but for historical reasons we instead have ${\displaystyle \scriptstyle \Gamma (z)\,=\,\int _{0}^{\infty }t^{z-1}e^{-t}dt}$ which begets ${\displaystyle \scriptstyle \Gamma (n)\,=\,(n-1)!}$.