MathorynMathematical Formula Database

Number Theory

Legendre's Formula

Legendre's formula gives the exponent of a prime pp in the factorisation of n!n!. It is used, for example, to count the trailing zeros of a factorial, which equal the exponent of 55.

vp(n!)=∑i≥1⌊npi⌋v_p(n!)=\sum_{i\ge1}\left\lfloor\frac{n}{p^i}\right\rfloor
LaTeXv_p(n!)=\sum_{i\ge1}\left\lfloor\frac{n}{p^i}\right\rfloor

Variables

vp(n!)v_p(n!)
exponent of p in n!
pp
prime
⌊⋅⌋\lfloor\cdot\rfloor
floor (round down)

Example

How many trailing zeros does 100!100! have?

  1. ⌊1005⌋+⌊10025⌋=20+4\left\lfloor\frac{100}{5}\right\rfloor+\left\lfloor\frac{100}{25}\right\rfloor=20+4.

Answer: 2424 trailing zeros.

Related formulas