[Solved] Project Euler #3 Python


I’m assuming you meant set n = 49.

Your outer while loop checks the condition i * i < n, which is not true for i == 7, so the outer loop breaks as soon as it hits 7. Change the < to <=.

However, your code isn’t correct in the first place– perhaps something like this is what you meant?

n = 600851475143
i = 2
factors = []

while (i <= n):
    while (n % i == 0):
        n = n / i
        factors.append(i)
    i = i + 1

print factors

11

solved Project Euler #3 Python