Here is my code for trying to solve Project Euler's third problem in Python:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
For some reason, this doesn't give an answer. I know that there is a double for loop, which is quite inefficient, but I don't know if the program is still running and trying to compute, or if there is an error. It might even be the break in the nested for loop that breaks all of the for loops. How can I be more efficient with this code? I'm not asking for a direct complete rewrite of my code, but little bits and pieces would be great. (And a few hints as well....!)
def prime_selector(primed_num):
factors = []
prime_factors = []
for x in range(1, primed_num + 1):
if primed_num % x == 0:
factors.append(x)
for i in factors:
if i > 1:
for j in range(2, i):
if i % j == 0:
break
else:
prime_factors.append(i)
prime_factors.sort(reverse=True)
print(prime_factors[0])
prime_selector(600851475143)