input: def largest_prime_factor(n: int) -> int:
      """Create a python program to find the largest prime factor of a number.
      >>> largest_prime_factor(331)
      331
      >>> largest_prime_factor(13195)
      29
      """
      import math
      factors = []
      for i in range(2, int(math.sqrt(n)) + 1):
          if n % i == 0:
              factors.append(i)
              factors.append(int(n/i))
      prime_factors = []
      for potential_factor in factors:
          is_prime = True
          for j in range(2,int(math.sqrt(potential_factor))+1):
              if potential_factor % j == 0 and potential_factor != j: 
                  is_prime = False
          if is_prime:
              prime_factors.append(potential_factor)
      return max(prime_factors) if prime_factors else n
output:     if n < 2:
          return n
      largest_factor = 1
      while n % 2 == 0:
          largest_factor = 2
          n //= 2
      for i in range(3, int(math.sqrt(n)) + 1, 2):
          while n % i == 0:
              largest_factor = i
              n //= i
      if n > 2:
          largest_factor = n
      return largest_factor