def factorial(n: int) -> int:
    """Iterative implementation of factorial algorithm.
    factorial(0) = 1
    factorial(1) = 1

    :param n: positive integer
    """
    result = 1
    for i in range(2, n + 1):
        result *= i
    return result