# highest power of Prime

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

.$p^r-1<N<p^r+p$

$p^r-p<N<p^r$

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?

-

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.