In general, the number n! has [n/p] + [n/p^2] + [n/p^3] + ... factors of p in it, where [n] denotes the "round down" or "greatest integer" function. At some point, the denominator will be bigger than the numerator, so you'l lget a string of zeros at the end....or, in fancy math-speak, this series will converge.
As a practical matter, just divide n by p, and write down that number. Then put a plus, divide the number BEFORE the plus by p, round down, and write that after the plus. Keep going until you get zeros.
Let's look at a number like 24, and ensure that we counted correctly. 24 = 2 * 2 * 2 * 3, so it should contribute THREE powers of 2. And 24 appears on the first three lists, but not on the last 2.