Código Python:
Ver originaldef factor(n):
"""return a list with the prime factors of n. Complexity: O(sqrt(n))"""
l = [] #List of factors
i = 2
while i * i <= n: #From 2 to sqrt(n)
while n % i == 0: #While i is factor of n, add to the list of factors.
l.append(i)
n /= i
i += 1
if n != 1: #If n isn't 1, then is a factor.
l.append(n)
return l
for i in range(2, 21):
print i, "->", factor(i)