Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find the prime factors of the number given
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i == 0:
n //= i
factors.append(i)
else:
i += 1
if n > 1:
factors.append(n)
return factors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment