I was checking the problems on http://projecteuler.net/
The third problem is as follows:
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
My solution code is below. But it is so slow that I think it will take weeks to complete. How can I improve it? Or is Python itself too slow to solve this problem?
def IsPrime(num):
if num < 2:
return False
if num == 2:
return True
else:
for div in range(2,num):
if num % div == 0:
return False
return True
GetInput = int (input ("Enter the number: "))
PrimeDivisors = []
for i in range(GetInput, 1, -1):
print(i)
if GetInput % i == 0 and IsPrime(i) is True:
PrimeDivisors.append(i)
break
else:
continue
print(PrimeDivisors)
print("The greatest prime divisor is:", max(PrimeDivisors))