Suppose we want to find how many times 3 divides 28!. Let's say by expanding 28!:
There are in total \(\lfloor \frac{n}{a} \rfloor\) multiples of \(a\) below \(n\), meaning there are \(\lfloor \frac{28}{3} \rfloor\) multiples of 3 below 28.
There are 9 numbers below 28 that are multiples of 3, which means there are 9 numbers in 28! which can be divided by 3:
Looking at the numbers above, you can see that there are some numbers which can be divided by 3 again. There are in total \(\lfloor \frac{28}{3^2} \rfloor\) (or 3) numbers below 28 that can be divided by 3 twice:
Now there are in total \(\lfloor \frac{28}{3^3} \rfloor\) (or 1) number below 28 that can be divided by 3 a third time:
Since \(\lfloor \frac{28}{3^4} \rfloor = 0\), then there are no numbers below 28 that can be divided by 3 four or more times. For the final number we calculated, if we take it's prime factorization, there would be no 3's because we have divided it all. This means 3 can divide 28 in total \(\lfloor \frac{28}{3^1} \rfloor + \lfloor \frac{28}{3^2} \rfloor + \lfloor \frac{28}{3^3} \rfloor \) = 13 times. Similarly, 5 can divide 28! in total \(\lfloor \frac{28}{5^1} \rfloor + \lfloor \frac{28}{5^2} \rfloor + \lfloor \frac{28}{5^3} \rfloor \ldots =\) 6 times. We can generalize this and say that prime \(p\) divides \(n!\) in total \(e\) times, where \(e\) is:
In other words the largest power of prime \(p\) that can divide \(n!\) is \(e\). Keep in mind this method only works with prime numbers. If we want to know how many times 4 divides 6! (or 720, we can manually check that it's 2 times, but \(\lfloor \frac{6}{4} \rfloor + \lfloor \frac{6}{4^2} \rfloor \ldots \) is 1. If we expand 6!, we see that there is only one number that can be divided by 4:
Although 4 can only divide 4, 2 can divide both 2 and 6. This means 720 can be divided by 4 once and 2 twice, but Legendre's formula only considers that one 4 and not the two 2's.