input: Write a function to find the largest prime factor of a given number. The function should return the largest prime number that divides the given number without leaving a remainder. If the number is prime itself, it should return the number itself as the largest prime factor.
  assert largest_prime_factor(331)==331
  assert largest_prime_factor(13195)==29
  assert largest_prime_factor(600851475143)==6857
  assert largest_prime_factor(49)==7
  assert largest_prime_factor(2)==2
output: def largest_prime_factor(n):
      factor = 2
      while factor * factor <= n:
          if n % factor == 0:
              n //= factor
          else:
              factor += 1
      return n