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