-7
votes

I have solved this but I was wondering what the most efficient method of solving this problem was (under 10s). Problem can be found at http://projecteuler.net/problem=3.

1
"Under 10s" in terms of what? - Matti Virkkunen
and you should at least post a link to the problem or the text - Samuele Mattiuzzo

1 Answers

13
votes

Here is probably the fastest and most compact way of doing it, taking just 141 milliseconds and giving the answer 6857.

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

n = 600851475143
i = 2
while i * i < n:
    while n % i == 0:
        n = n / i
    i = i + 1

print n

Code taken from here