How to find maximum $x$ that $k^x$ divides $n!$ Given numbers $k$ and $n$
how can I find the maximum $x$ where:
$n! \equiv\ 0 \pmod{k^x}$?
I tried to compute $n!$
and then make binary search over some range $[0,1000]$ for example 
compute $k^{500}$
if $n!$ mod $k^{500}$ is greater than $0$ then I compute $k^{250}$ and so on
but I have to compute every time value $n!$ (storing it in bigint and everytime manipulate with it is a little ridiculous)
And time to compute $n!$ is $O(n)$, so very bad.
Is there any faster, math solution to this problem? Math friends?:)
Cheers Chris

Here is a possible approach. If $p$ is prime, the largest value of $p$ dividing $n!$ is
$$\sum_{k=1}^\infty \left\lfloor {n\over p^k}\right\rfloor.$$
If the number $k$ you are considering is easily factorable into primes, you can adapt this result to your needs.
