input: 
  from typing import Optional
  
  def largest_prime_factor(n: int) -> Optional[int]:
      """Find and return the largest prime factor of a given number. 
      Return None if no prime factors are found.
      >>> largest_prime_factor(331)
      331
      >>> largest_prime_factor(27)
      3
      >>> largest_prime_factor(100)
      5
      """
      factors = []
      for i in range(2, int(math.sqrt(n)) + 1):
          if n % i == 0:
              factors.append(i)
              factors.append(int(n/i))
      
      if not factors:
          return None if n <= 1 else n
      
      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 None if n <= 1 else n
      
      return max(prime_factors)
  
  import math
  print(largest_prime_factor(331))
  
output:     
      import math
      print(largest_prime_factor(331))
  