Calculate the factorial of a given number