prime factors example in readme
dcontant opened this issue · comments
denys commented
the example does not return the prime factors of n
try this instead
def prime_factors(n):
with timy.Timer('Factors') as timer:
i = 2
factors = []
def add_factor(n):
factors.append(n)
timer.track('Found a factor')
while i * i <= n:
if n % i == 0:
add_factor(i)
n //= i
else:
i += 1
return factors + [n]
factors = prime_factors(600851475143)
print(factors)
Ramon Saraiva commented
thanks for catching it