Project Euler #3: Largest prime factor

  • + 0 comments

    This was a bit complex. but passed all tests

    def factor(n):
        (res_list, i)=([1],2)
        while n != 1:
            if n%i == 0:
                while n%i == 0:
                    n = n//i            
                res_list.append(i)
            i = i+1 if i*i <= n else n
        return res_list