TITLE: Understanding the proof of a formula for $p^e\Vert n!$
QUESTION [9 upvotes]: This is a proof from a book on number theory I'm reading. I'm having a hard time following. I think there's a variable here that means two different things at two different times...
Theorem:
If n is a positive integer and p is a prime, then $p^e \vert\vert n!$, where $e=\lfloor\frac{n}{p}\rfloor + \lfloor\frac{n}{p^2}\rfloor + \dots + \lfloor\frac{n}{p^r}\rfloor$ and r is determined by n by the inequality $p^r \le n <p^{r+1}$
Proof:
For a given integer k, the multiples of $p^k$ that do not exceed  n are $p^k, 2p^k, \cdots, qp^k$ , where q is the largest integer such that $qp^k \le n$. But this says that q is the largest integer not exceeding $n/p^k$, so that  $q= \lfloor n/p^k \rfloor$. Thus, $\lfloor n/p^k\rfloor$ gives the number of positive multiples of $p^k$ that do not exceed n.

Interlude:
I understand the proof so far. We've simply chosen some power of p
  and shown that $\lfloor n/p^k \rfloor$ is the largest integer that we can multiply by $p^k$ and stay under n. Here's where I start to get confused.

Now, if $1 \le m \le n$, then $m=qp^k$ with $(q,p) = 1, 0 \le k \le r$, and m contributes precisely k to the total exponent e with which p appears in the canonical representation of n!

Interlude 2:
How exactly does $m=qp^k$ follow from $1 \le m \le n$? Also, this q seems to mean something other than $\lfloor n/p^k\rfloor$ since we seem to be considering the set of all numbers less than or equal to n and greater than or equal to 1 that have the form $m=qp^k$?

Moreover, m is counted precisely k times by the sum
$\lfloor\frac{n}{p}\rfloor + \lfloor\frac{n}{p^2}\rfloor + \dots + \lfloor\frac{n}{p^r}\rfloor$, 
once as a multiple of p, once as a multiple of $p^2$, ... , once as a multiple of $p^k$, and no more. Of course, if $k=0$, then m is not counted in the sum. Therefore, the sum above accounts exactly for the contribution of each m between 1 and n to the exponent e as claimed.

Interlude 3:
What exactly is meant here by counted? I really don't understand the last part of this proof at all...

REPLY [3 votes]: One can give a very nice proof using the Von Mangoldt function. We define $\Lambda(n)$, as follows. It equals $\log p$ is $n=p^k$ for some prime $p$; and $0$ else. Observe then that if $n=p_1^{\alpha_1}\cdots p_k^{\alpha_k}$ then $$\log n=\sum_{i=1}^k \alpha_i \log p_i= \sum_{d\mid n}\Lambda (d)$$ 
The last equality holds by observing we have $\log p$ accounted $\alpha_i$ times for $p^j\mid n,j=1,\ldots,\alpha_i$, and any composite divisor dies. Now, $$\log m!=\sum_{b=1}^m\log b=\sum_{b=1}^m\sum_{d\mid b}\Lambda(d)$$
It suffices we note that $$\sum_{b=1}^m\sum_{d\mid b}\Lambda(d)=\sum_{b=1}^m \sum_{d\geqslant 1}[d\mid b]\Lambda(d)=\sum_{d\geqslant 1}\Lambda(d)\sum_{b=1}^m[d\mid b]$$
and of course $\displaystyle\sum_{b=1}^m[d\mid b]=\left\lfloor \dfrac m d\right\rfloor$, since it counts the number of multiples of $d$ less than $m$. Thus
$$\log m!=\sum_{b=1}^m\log b=\sum_{d\geqslant 1} \Lambda(d)\left\lfloor\frac md \right\rfloor$$ 
Since the Von Mangoldt function is nonzero only at prime powers, $$\log m!=\sum_{i\geqslant 1}\sum_{p\;\rm prime}\Lambda(p^i)\left\lfloor\frac{m}{p^i}\right\rfloor=\sum_{i\geqslant 1}\sum_{p\;\rm prime}\log p\left\lfloor\frac{m}{p^i}\right\rfloor$$
Hence the result: if we define $v_p(n)=\displaystyle\sum_{i\geqslant 1} \left\lfloor\frac{n}{p^i}\right\rfloor$ $$n!=\prod_{p\rm\; prime}p^{v_p(n)}$$