info prev up next book cdrom email home

Factorial

The factorial $n!$ is defined for a Positive Integer $n$ as

\begin{displaymath}
n!\equiv \cases{
n\cdot(n-1)\cdots 2 \cdot 1 & $n=1, 2, \ldots$\cr
1 & $n = 0$.\cr}
\end{displaymath} (1)

The first few factorials for $n=0$, 1, 2, ... are 1, 1, 2, 6, 24, 120, ... (Sloane's A000142). An older Notation for the factorial is \BoxedEPSF{FactorialOld.epsf scaled 1000} (Dudeney 1970, Gardner 1978, Conway and Guy 1996).


As $n$ grows large, factorials begin acquiring tails of trailing Zeros. To calculate the number of trailing Zeros for $n!$, use

\begin{displaymath}
Z=\sum_{k=1}^{k_{\rm max}} \left\lfloor{n\over 5^k}\right\rfloor ,
\end{displaymath} (2)

where
\begin{displaymath}
k_{\rm max}\equiv \left\lfloor{\ln n\over\ln 5}\right\rfloor
\end{displaymath} (3)

and $\left\lfloor{x}\right\rfloor $ is the Floor Function (Gardner 1978, p. 63; Ogilvy and Anderson 1988, pp. 112-114). For $n=1$, 2, ..., the number of trailing zeros are 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, ... (Sloane's A027868). This is a special application of the general result that the Power of a Prime $p$ dividing $n!$ is
\begin{displaymath}
\epsilon_p(n)=\sum_{r\geq 0}\left\lfloor{n\over p^r}\right\rfloor
\end{displaymath} (4)

(Graham et al. 1994, Vardi 1991). Stated another way, the exact Power of a Prime $p$ which divides $n!$ is
\begin{displaymath}
{n-\hbox{sum of digits of the base-$p$\ representation of $n$}\over p-1}.
\end{displaymath} (5)


By noting that

\begin{displaymath}
n! = \Gamma(n+1),
\end{displaymath} (6)

where $\Gamma(n)$ is the Gamma Function for Integers $n$, the definition can be generalized to Complex values
\begin{displaymath}
z! \equiv \Gamma (z+1) \equiv \int^\infty_0 e^{-t}t^z\,dt.
\end{displaymath} (7)

This defines $z!$ for all Complex values of $z$, except when $z$ is a Negative Integer, in which case $z!=\infty$. Using the identities for Gamma Functions, the values of $({\textstyle{1\over 2}}n)!$ (half integral values) can be written explicitly
$\displaystyle (-{\textstyle{1\over 2}})!$ $\textstyle =$ $\displaystyle \sqrt{\pi}$ (8)
$\displaystyle ({\textstyle{1\over 2}})!$ $\textstyle =$ $\displaystyle {\textstyle{1\over 2}}\sqrt{\pi}$ (9)
$\displaystyle (n-{\textstyle{1\over 2}})!$ $\textstyle =$ $\displaystyle {\sqrt{\pi}\over 2^n} (2n-1)!!$ (10)
$\displaystyle (n+{\textstyle{1\over 2}})!$ $\textstyle =$ $\displaystyle {\sqrt{\pi}\over 2^{n+1}} (2n+1)!!,$ (11)

where $n!!$ is a Double Factorial.


For Integers $s$ and $n$ with $s < n$,

\begin{displaymath}
{(s-n)!\over (2s-2n)!} = {(-1)^{n-s}(2n-2s)!\over (n-s)!}.
\end{displaymath} (12)

The Logarithm of $z!$ is frequently encountered


$\displaystyle \ln(z!)$ $\textstyle =$ $\displaystyle {1\over 2}\ln\left[{\pi z\over\sin(\pi z)}\right]-\gamma-\sum_{n=1}^\infty {\zeta(2n+1)\over 2n+1} z^{2n+1}$ (13)
  $\textstyle =$ $\displaystyle {1\over 2}\ln\left[{\pi z\over\sin(\pi z)}\right]-{1\over 2}\ln\l...
... 1-z}\right)+(1-\gamma)z-\sum_{n=1}^\infty [\zeta(2n+1)-1] {z^{2n+1}\over 2n+1}$ (14)
  $\textstyle =$ $\displaystyle \ln\left[{\lim_{n\to\infty} {n!\over (z+1)(z+2)\cdots (z+n)} n^z}\right]$ (15)
  $\textstyle =$ $\displaystyle \lim_{n\to\infty} [\ln(n!)+z\ln n-\ln(z+1)-\ln(z+2)-\ldots -\ln(z+n)]$ (16)
  $\textstyle =$ $\displaystyle \sum_{n=1}^\infty {z^n\over n!} F_{n-1}(0)$ (17)
  $\textstyle =$ $\displaystyle -\gamma z + \sum_{n=2}^\infty (-1)^n {z^n\over n} \zeta(n)$ (18)
  $\textstyle =$ $\displaystyle -\ln(1+z)+z(1-\gamma) + \sum_{n=2}^\infty (-1)^n[\zeta(n)-1] {z^n\over n},$ (19)

where $\gamma$ is the Euler-Mascheroni Constant, $\zeta$ is the Riemann Zeta Function, and $F_n$ is the Polygamma Function. The factorial can be expanded in a series


\begin{displaymath}
z! = \sqrt{2\pi}\, z^{z+1/2}e^{-z}(1 + {\textstyle{1\over 12...
...er 288}}z^{-2} - {\textstyle{139\over 51840}}z^{-3} + \ldots).
\end{displaymath} (20)

Stirling's Series gives the series expansion for $\ln(z!)$,


$\displaystyle \ln(z!)$ $\textstyle =$ $\displaystyle {\textstyle{1\over 2}}\ln(2\pi) + \left({z+ {\textstyle{1\over 2}}}\right)\ln z-z+ {B_2\over 2z} + \ldots + {B_{2n}\over 2n(2n-1)z^{2n-1}} + \ldots$  
  $\textstyle =$ $\displaystyle {\textstyle{1\over 2}}\ln(2\pi) + \left({z+{\textstyle{1\over 2}}...
...1} - {\textstyle{1\over 360}}z^{-3} + {\textstyle{1\over 1260}}z^{-5} - \ldots,$ (21)

where $B_n$ is a Bernoulli Number.


Identities satisfied by sums of factorials include

$\displaystyle \sum_{k=0}^\infty {1\over k!}$ $\textstyle =$ $\displaystyle e =2.718281828\ldots$ (22)
$\displaystyle \sum_{k=0}^\infty {(-1)^k\over k!}$ $\textstyle =$ $\displaystyle e^{-1} =0.3678794411\ldots$ (23)
$\displaystyle \sum_{k=0}^\infty {1\over (k!)^2}$ $\textstyle =$ $\displaystyle I_0(2) =2.279585302\ldots$ (24)
$\displaystyle \sum_{k=0}^\infty {(-1)^k\over (k!)^2}$ $\textstyle =$ $\displaystyle J_0(2) =0.2238907791\ldots$ (25)
$\displaystyle \sum_{k=0}^\infty {1\over (2k)!}$ $\textstyle =$ $\displaystyle \cosh 1 =1.543080634\ldots$ (26)
$\displaystyle \sum_{k=0}^\infty {(-1)^k\over (2k)!}$ $\textstyle =$ $\displaystyle \cos 1 =0.5403023058\ldots$ (27)
$\displaystyle \sum_{k=0}^\infty {1\over (2k+1)!}$ $\textstyle =$ $\displaystyle \sinh 1 =1.175201193\ldots$ (28)
$\displaystyle \sum_{k=0}^\infty {(-1)^k\over (2k+1)!}$ $\textstyle =$ $\displaystyle \sin 1 =0.8414709848\ldots$ (29)

(Spanier and Oldham 1987), where $I_0$ is a Modified Bessel Function of the First Kind, $J_0$ is a Bessel Function of the First Kind, cosh is the Hyperbolic Cosine, cos is the Cosine, sinh is the Hyperbolic Sine, and sin is the Sine.


Let $h$ be the exponent of the greatest Power of a Prime $p$ dividing $n!$. Then

\begin{displaymath}
h=\sum_{\scriptstyle i=1 \atop \scriptstyle p^i\leq n} \left\lfloor{n\over p^i}\right\rfloor .
\end{displaymath} (30)

Let $g$ be the number of 1s in the Binary representation of $n$. Then
\begin{displaymath}
g+h=n
\end{displaymath} (31)

(Honsberger 1976). In general, as discovered by Legendre in 1808, the Power $m$ of the Prime $p$ dividing $n!$ is given by
\begin{displaymath}
m=\sum_{k=0}^\infty \left\lfloor{n\over p^k}\right\rfloor = {n-(n_0+n_1+\ldots+n_N)\over p-1},
\end{displaymath} (32)

where the Integers $n_1$, ..., $n_N$ are the digits of $n$ in base $p$ (Ribenboim 1989).


The sum-of-factorials function is defined by

$\displaystyle \Sigma(n)$ $\textstyle \equiv$ $\displaystyle \sum_{k=1}^n k!$  
  $\textstyle =$ $\displaystyle {-e+\mathop{\rm ei}\nolimits (1)+\pi i+{\rm E}_{2n+1}(-1)\Gamma(n+2)\over e},$ (33)
  $\textstyle =$ $\displaystyle {-e+\mathop{\rm ei}\nolimits (1)+\Re[{\rm E}_{2n+1}(-1)]\Gamma(n+2)\over e},$ (34)

where $\mathop{\rm ei}\nolimits (1)\approx 1.89512$ is the Exponential Integral, ${\rm E}_n$ is the En-Function, and i is the Imaginary Number. The first few values are 1, 3, 9, 33, 153, 873, 5913, 46233, 409113, ... (Sloane's A007489). $\Sigma(n)$ cannot be written as a hypergeometric term plus a constant (Petkovsek et al. 1996). However the sum
\begin{displaymath}
\Sigma'(n)\equiv \sum_{k=1}^n kk!=(n+1)!-1
\end{displaymath} (35)

has a simple form, with the first few values being 1, 5, 23, 119, 719, 5039, ... (Sloane's A033312).


The numbers $n!+1$ are prime for $n=1$, 2, 3, 11, 27, 37, 41, 73, 77, 116, 154, ... (Sloane's A002981), and the numbers $n!-1$ are prime for $n=3$, 4, 6, 7, 12, 14, 30, 32, 33, 38, 94, 166, ... (Sloane's A002982). In general, the power-product sequences (Mudge 1997) are given by $S_k^\pm(n)=(n!)^k\pm 1$. The first few terms of $S_2^+(n)$ are 2, 5, 37, 577, 14401, 518401, ... (Sloane's A020549), and $S_2^+(n)$ is Prime for $n=1$, 2, 3, 4, 5, 9, 10, 11, 13, 24, 65, 76, ... (Sloane's A046029). The first few terms of $S_2^-(n)$ are 0, 3, 35, 575, 14399, 518399, ... (Sloane's A046032), but $S_2^-(n)$ is Prime for only $n=2$ since $S_2^-(n)=(n!)^2-1=(n!+1)(n!-1)$ for $n>2$. The first few terms of $S_3^-(n)$ are 0, 7, 215, 13823, 1727999, ... (Sloane's A0460333), and the first few terms of $S_3^+(n)$ are 2, 9, 217, 13825, 1728001, ... (Sloane's A019514).


There are only four Integers equal to the sum of the factorials of their digits. Such numbers are called Factorions. While no factorial is a Square Number, D. Hoey listed sums $<10^{12}$ of distinct factorials which give Square Numbers, and J.  McCranie gave the one additional sum less than $21!=5.1\times 10^{19}$:

$\displaystyle 0!+1!+2!$ $\textstyle =$ $\displaystyle 2^2$  
$\displaystyle 1!+2!+3!$ $\textstyle =$ $\displaystyle 3^2$  
$\displaystyle 1!+4!$ $\textstyle =$ $\displaystyle 5^2$  
$\displaystyle 1!+5!$ $\textstyle =$ $\displaystyle 11^2$  
$\displaystyle 4!+5!$ $\textstyle =$ $\displaystyle 12^2$  
$\displaystyle 1!+2!+3!+6!$ $\textstyle =$ $\displaystyle 27^2$  
$\displaystyle 1!+5!+6!$ $\textstyle =$ $\displaystyle 29^2$  
$\displaystyle 1!+7!$ $\textstyle =$ $\displaystyle 71^2$  
$\displaystyle 4!+5!+7!$ $\textstyle =$ $\displaystyle 72^2$  
$\displaystyle 1!+2!+3!+7!+8!$ $\textstyle =$ $\displaystyle 213^2$  
$\displaystyle 1!+4!+5!+6!+7!+8!$ $\textstyle =$ $\displaystyle 215^2$  
$\displaystyle 1!+2!+3!+6!+9!$ $\textstyle =$ $\displaystyle 603^2$  
$\displaystyle 1!+4!+8!+9!$ $\textstyle =$ $\displaystyle 635^2$  
$\displaystyle 1!+2!+3!+6!+7!+8!+10!$ $\textstyle =$ $\displaystyle 1917^2$  


\begin{displaymath}
1!+2!+3!+7!+8!+9!+10!+11!+12!+13!+14!+15! = 1183893^2
\end{displaymath}

(Sloane's A014597). The first few values for which the alternating Sum
\begin{displaymath}
\sum_{i=1}^n (-1)^{n-i}i!
\end{displaymath} (36)

is Prime are 3, 4, 5, 6, 7, 8, 41, 59, 61, 105, 160, ... (Sloane's A014615, Guy 1994, p. 100). The only known factorials which are products of factorial in an Arithmetic Sequence are
$\displaystyle 0!1!$ $\textstyle =$ $\displaystyle 1!$  
$\displaystyle 1!2!$ $\textstyle =$ $\displaystyle 2!$  
$\displaystyle 0!1!2!$ $\textstyle =$ $\displaystyle 2!$  
$\displaystyle 6!7!$ $\textstyle =$ $\displaystyle 10!$  
$\displaystyle 1!3!5!$ $\textstyle =$ $\displaystyle 6!$  
$\displaystyle 1!3!5!7!$ $\textstyle =$ $\displaystyle 10!$  

(Madachy 1979).


There are no identities of the form

\begin{displaymath}
n!={a_1}!{a_2}!\cdots{a_r}!
\end{displaymath} (37)

for $r\geq 2$ with $a_i\geq a_j\geq 2$ for $i<j$ for $n\leq 18160$ except
$\displaystyle 9!$ $\textstyle =$ $\displaystyle 7!3!3!2!$ (38)
$\displaystyle 10!$ $\textstyle =$ $\displaystyle 7!6!=7!5!3!$ (39)
$\displaystyle 16!$ $\textstyle =$ $\displaystyle 14!5!2!$ (40)

(Guy 1994, p. 80).


There are three numbers less than 200,000 for which

\begin{displaymath}
(n-1)!+1\equiv 0\ \left({{\rm mod\ } {n^2}}\right),
\end{displaymath} (41)

namely 5, 13, and 563 (Le Lionnais 1983). Brown Numbers are pairs $(m,n)$ of Integers satisfying the condition of Brocard's Problem, i.e., such that
\begin{displaymath}
n!+1=m^2.
\end{displaymath} (42)

Only three such numbers are known: (5, 4), (11, 5), (71, 7). Erdös conjectured that these are the only three such pairs (Guy 1994, p. 193).

See also Alladi-Grinstead Constant, Brocard's Problem, Brown Numbers, Double Factorial, Factorial Prime, Factorion, Gamma Function, Hyperfactorial, Multifactorial, Pochhammer Symbol, Primorial, Roman Factorial, Stirling's Series, Subfactorial, Superfactorial


References

Conway, J. H. and Guy, R. K. ``Factorial Numbers.'' In The Book of Numbers. New York: Springer-Verlag, pp. 65-66, 1996.

Dudeney, H. E. Amusements in Mathematics. New York: Dover, p. 96, 1970.

Gardner, M. ``Factorial Oddities.'' Ch. 4 in Mathematical Magic Show: More Puzzles, Games, Diversions, Illusions and Other Mathematical Sleight-of-Mind from Scientific American. New York: Vintage, pp. 50-65, 1978.

Graham, R. L.; Knuth, D. E.; and Patashnik, O. ``Factorial Factors.'' §4.4 in Concrete Mathematics: A Foundation for Computer Science. Reading, MA: Addison-Wesley, pp. 111--115, 1990.

Guy, R. K. ``Equal Products of Factorials,'' ``Alternating Sums of Factorials,'' and ``Equations Involving Factorial $n$.'' §B23, B43, and D25 in Unsolved Problems in Number Theory, 2nd ed. New York: Springer-Verlag, pp. 80, 100, and 193-194, 1994.

Honsberger, R. Mathematical Gems II. Washington, DC: Math. Assoc. Amer., p. 2, 1976.

Le Lionnais, F. Les nombres remarquables. Paris: Hermann, p. 56, 1983.

Leyland, P. ftp://sable.ox.ac.uk/pub/math/factors/factorial-.Z and ftp://sable.ox.ac.uk/pub/math/factors/factorial+.Z.

Madachy, J. S. Madachy's Mathematical Recreations. New York: Dover, p. 174, 1979.

Mudge, M. ``Not Numerology but Numeralogy!'' Personal Computer World, 279-280, 1997.

Ogilvy, C. S. and Anderson, J. T. Excursions in Number Theory. New York: Dover, 1988.

Petkovsek, M.; Wilf, H. S.; and Zeilberger, D. A=B. Wellesley, MA: A. K. Peters, p. 86, 1996.

Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. ``Gamma Function, Beta Function, Factorials, Binomial Coefficients.'' §6.1 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 206-209, 1992.

Ribenboim, P. The Book of Prime Number Records, 2nd ed. New York: Springer-Verlag, pp. 22-24, 1989.

Sloane, N. J. A. Sequences A014615, A014597, A033312, A020549, A000142/M1675, and A007489/M2818 in ``An On-Line Version of the Encyclopedia of Integer Sequences.'' http://www.research.att.com/~njas/sequences/eisonline.html.

Spanier, J. and Oldham, K. B. ``The Factorial Function $n!$ and Its Reciprocal.'' Ch. 2 in An Atlas of Functions. Washington, DC: Hemisphere, pp. 19-33, 1987.

Vardi, I. Computational Recreations in Mathematica. Reading, MA: Addison-Wesley, p. 67, 1991.



info prev up next book cdrom email home

© 1996-9 Eric W. Weisstein
1999-05-26