Calculated the factorial of a given number.