I am working on Project on Euler Problem 3,
The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?
The code that I came up with is as follows:
def q_prime(a):
if a == 2:
return True
elif a < 2:
return False
for i in range(2,a):
if a%i == 0:
return False
else:
return True
def prime_factor(x):
prime_factors =[]
for i in range(1,x):
if q_prime(i) == True and x%i == 0:
prime_factors.append(i)
return prime_factors
Calling this function of 13195 gave me [5,7,13,29] as expected. I tried some other combinations like 1035 which gives [3,5,23]. However, when I call this function on 600851475143, I get no output. Moreover, I get no error message either. It runs for a while, and simple restarts shell
I know this is not an elegant code, and I am guessing brute forcing my way through a problem like this for a large number is causing this problem? What exactly is going on?