def factorial(n):
    """
    Computes the factorial of n.
    """
    if n < 0:
       raise ValueError('received negative input')
    result = 1
    for i in range(1, n + 1):
       result *= i
    return result