# Counting number of occurrences of a number in a factorial

Consider that I want to count the number of times 360 occurs in 520!

$$360 = 2^3 \cdot 3^2 \cdot 5^1$$

$$520! = 1\cdot2\cdot3\cdot4\cdot\cdots$$

As it can be noticed, $$2$$ occurs at least $$3$$ times before $$5.$$ As for $$3^2,$$ it is doubtful as to how many times it occurs before $$5.$$ So I checked for both $$3^2$$ and $$5.$$ $$5$$ occurs $$128$$ times in $$520!$$ and $$3^2$$ occurs $$128$$ times as well. On the other hand, $$2^3$$ appears $$172$$ times. So it can be safely said that $$360$$ occurs $$128$$ times in $$520!$$

My question is since it is obvious that $$2$$ appears at least thrice before $$5,$$ could the calculation of the number of occurrences for $$2^3$$ be ignored? Can this be done in all scenarios? If not, what can be some exceptions?

• Hint: use de Polignac's Formula – lulu Feb 3 at 17:38
• That is what I used to find the number of occurrences of all the exponents mentioned. – Aamir Khan Feb 3 at 17:39
• Well, in general i expect you have to look at all the primes. I don't think there is a shortcut. It's so easy to get all the individual orders, that I'm not sure it's worth spending a lot of time trying to avoid looking at one prime or another. – lulu Feb 3 at 17:43