input: Write a function to find the largest prime factor of a given number. Return the largest prime factor. If the input number is prime, then return the number itself.
  assert largest_prime_factor(331)==331
  assert largest_prime_factor(13195)==29
  assert largest_prime_factor(600851475143)==6857
  assert largest_prime_factor(2)==2
  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
      if n > 1:
          return n
      return factor - 1