Exponent of Prime in a Factorial I was just trying to work out the exponent for $7$ in the number $343!$. I think the right technique is $$\frac{343}{7}+\frac{343}{7^2}+\frac{343}{7^3}=57.$$ If this is right, can the technique be generalized to $p$ a prime number, $n$ any positive integer, then the exponent of $p$ in $n!$ will be $$\sum_{k=1}^\infty\left\lfloor\frac{n}{p^k}\right\rfloor\quad ?$$ Here, $\lfloor\cdot\rfloor$ denotes the integer less than or equal to $\cdot$ .
Obviously the sum is finite, but I didn't know if it was correct (since its veracity depends on my first solution anyway).
 A: Both the solution and its generalization are correct, as @M.B. points out in the comments to the original post. As a corollary, this provides an easy way to count the number of trailing zeros.
A: Why is it so ?
To form the value of $n$, all integers $1,2,\cdots n$ enter into play as factors, and some of them are multiples of $p$.
How many of them ? Well, $n'=\lfloor\dfrac np\rfloor$.
Then, if you discard the other factors and simplify the remaining product by $p^{n'}$, you end up with the expression of $n'!$. Then you repeat the process, until all factors are consumed.
For example, with $n=13,p=3$:
$$13!=1\cdot2\cdot\color{green}3\cdot4\cdot5\cdot\color{green}6\cdot7\cdot8\cdot\color{green}9\cdot10\cdot11\cdot\color{green}{12}\cdot13$$
has $4$ multiples of $3$ and remaining factors
$$4!=1\cdot2\cdot\color{green}3\cdot4$$
that has $1$ other factor and remainder $$1!=1.$$
This reasoning establishes the recurrence
$$N_p(n!)=\lfloor\frac np\rfloor+N_p\left(\lfloor\frac np\rfloor!\right),$$
with solution
$$N_p(n!)=\sum_{k=1}^{p^k\le n}\lfloor\dfrac n{p^k}\rfloor.$$
