Project Euler #3 with python – MOST EFFICIENT METHOD

Question:

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 Projecteuler.

Asked By: user1945376

||

Answers:

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

Answered By: bazite
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.