Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to find the highest power of prime $p$ in $N!$, when



I know that the highest power of prime contained in $N!$ is given by:

$$s_p(N!) = \left \lfloor \frac{N}{p} \right \rfloor + \left \lfloor \frac{N}{p^2} \right \rfloor + \left \lfloor \frac{N}{p^3} \right \rfloor + \cdots$$ But how to apply the restrictions?

share|cite|improve this question
up vote 1 down vote accepted

The formula is true for all $N \geq 0$; the restriction does not affect its truth value. However, we can simplify things.

  • We see that $s_p(N!)=s_p((N-(N \text{ mod } p))!)$. Since the factors $N-(N \text{ mod } p)+1,N-(N \text{ mod } p)+2,\ldots,N$ make no contribution to $s_p(N!)$, as they are coprime to $p$. [Here $N \text{ mod } p$ represents the residue in $\{0,1,\ldots,n-1\}$.]

    E.g. in the first case, this means $s_p(N!)=s_p(p^r!)$.

  • We can "chop off" terms $\lfloor N/p^k \rfloor$ for which $N/p^k<1$, since the floor function will make them zero.

    So, when applying the formula to $p^r!$, we need only account for the terms $\lfloor p^r/p^k \rfloor$ where $1 \leq k \leq r$. Further, in this case, $p^k$ divides $p^r$, so the floor functions are unnecessary.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.