I'm trying to find a number's max prime factor. Here is my code, but I don't know are my codes working correctly or not because I'm getting MemoryError all the time;
lst = []
for x in range(3,round(600851475143**0.5)+1):
for y in range(2,x+1):
if x%y==0:
for z in range(2,x+1):
if x%z!=0:
lst.append(x)
print (max(lst))
Here is the traceback;
>>>
Traceback (most recent call last):
File "C:--------", line 19, in <module>
lst.append(x)
MemoryError
>>>
After 20-30 seconds process, I got this error.How to avoid this one?
Edit: Actually, I guess that it may be MemoryError so as you see I put in the first range
function, square root of that number 600851475143**0.5
. Then I use round
to aviod from float
. But I still got MemoryError.