I have to find the largest prime factor of a number, so I wrote the code below:
num = int(input())
start = num-2
while start>=2:
if num%start==0 and (2**(start-1))%start==1:
print(start)
break
else:
start-=1
It works when the input isn't large. Ex. 12351264 => 128659 or 13195=>29, but I entered 600851475143 and it didn't respond for 10-15 minutes so I restart the kernel. Cpu and memory usages weren't high at that moment but fans start to make a bit noise. What is the problem with the code and how can I fix it?
Note: I used Fermat’s Little Theorem in the second condition.