input: def largest_prime_factor(n: int) -> int:
      """ Find the largest prime factor of the given number n.
      >>> largest_prime_factor(331)
      331
      """
output:     if n <= 1:
          return None
      largest_factor = 1
      # Check for and remove factors of 2
      while n % 2 == 0:
          largest_factor = 2
          n //= 2
      # Check for odd factors from 3 upwards
      factor = 3
      while factor * factor <= n:
          while n % factor == 0:
              largest_factor = factor
              n //= factor
          factor += 2
      if n > 1:
          largest_factor = n
      return largest_factor