input: Write a function to find the largest prime factor of a given number. If the number is 1, return 1. If the number is negative or zero, return 0. If the number is a prime number itself, return the number.
  assert largest_prime_factor(331) == 331
  assert largest_prime_factor(1) == 1
  assert largest_prime_factor(-5) == 0
  assert largest_prime_factor(29) == 29
  assert largest_prime_factor(48) == 3
output: def largest_prime_factor(n):
      if n <= 0:
          return 0
      if n == 1:
          return 1
      
      def is_prime(num):
          if num <= 1:
              return False
          if num <= 3:
              return True
          if num % 2 == 0 or num % 3 == 0:
              return False
          i = 5
          while i * i <= num:
              if num % i == 0 or num % (i + 2) == 0:
                  return False
              i += 6
          return True
      
      if is_prime(n):
          return n
      
      largest_factor = 1
      for i in range(2, int(n**0.5) + 1):
          if n % i == 0:
              if is_prime(i):
                  largest_factor = max(largest_factor, i)
              if is_prime(n // i):
                  largest_factor = max(largest_factor, n // i)
      
      return largest_factor