input: Write a function to determine the largest prime factor of a given number. The function should return the largest prime factor. If the number is prime or 1, the function should return the number itself.
  assert largest_prime_factor(331) == 331
  assert largest_prime_factor(100) == 5
  assert largest_prime_factor(7919) == 7919
  assert largest_prime_factor(250) == 5
  assert largest_prime_factor(1) == 1
output: def largest_prime_factor(n):
      if n <= 1:
          return n
      factor = 2
      while factor * factor <= n:
          while (n % factor) == 0:
              n //= factor
          factor += 1
      return n