What makes such an algorithm have better efficiency is that we can compute the unique prime factorisation of a factorial first and then use it to compute the factorial. I'll go through the steps to do this now.

Let's consider $9!$ as an example

The naive way to compute it is by the definition, $$9! = 9\cdot 8\cdot7\cdot6\cdot5\cdot4\cdot3\cdot2 = \prod_{k=2}^{9}k$$ Instead let's try compute it by factoring first.

We need to count the amount of times each prime divides into $9!$, let's consider the explicit version of $9!$ above.

Starting with $2$, it divides into $2,4,6,8$, but also can divide once more into $4,8$, and can divide into $8$ a third time. So the number of times 2 divides $9!$ is $4+2+1=7$, i.e $2^7$ divides $9!$.

Next prime is $3$, it divides into $3,6,9$ and divides once more into $9$, so number of times $3$ divides $9!$ is $3+1=4$, i.e $3^4$ divides $9!$.

Next primes are $5$ and $7$, both of which only divide once into $9!$. Putting this together we get $$9! = 2^7 \cdot 3^4 \cdot 5^1 \cdot 7^1 = 128\cdot81\cdot5\cdot7 = 362880$$