Work out largest prime factor of a number
There are many questions about Project Euler 3 on this site already.  The trick is to pick an algorithm that…


Reduces n whenever you find a factor, so that you don't need to consider factors anywhere near as large as 600851475143
Only finds prime factors, and never composite factors




from itertools import chain, count

def biggest_prime_factor(n):
    for f in chain([2], count(3, 2)):
        while n % f == 0:
            n //= f
            if f &gt;= n ** 0.5:
                return f if n == 1 else n

print(biggest_prime_factor(600851475143))