input: Write a function to find the largest prime factor of a given number. If the number is negative, return -1 indicating invalid input. If the number is 1, return 1 since 1 is not considered a prime number.
  
  
  def largest_prime_factor(n):
      if n < 0:
          return -1
      if n == 1:
          return 1
      
      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)
      
      if not prime_factors:
          return n
      return max(prime_factors)
  
  assert largest_prime_factor(331) == 331
  assert largest_prime_factor(100) == 5
  assert largest_prime_factor(13195) == 29
  assert largest_prime_factor(1) == 1
  assert largest_prime_factor(-5) == -1
  
output: def largest_prime_factor(n):
      if n < 0:
          return -1
      if n == 1:
          return 1
      
      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)
      
      if not prime_factors:
          return n
      return max(prime_factors)