def largest_prime_factor(n: int) -> int:
    """
    Returns the largest prime factor of n
    """
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
    return n