I was trying Project Euler Problem 3: What is the largest prime factor of the number 600851475143 ? My code is working for random 4 digit numbers. However my code is just not compiling. It has been 15 minutes now.
I think this has something to do with "efficiency of algorithms". I am about to join college for Computer Science and Engineering course so I thought it would be a great idea if I practiced coding in Python. Is my code not efficient? Should I study CLRS now before going any further? I have already completed the basics of Python (from Udacity).
#What is the largest prime factor of the number 600851475143 ?
factorlist=[]
def prime(num): #primetesterfunction
primecount=0
for factors in range(2,num):
if num%factors==0:
return False
else:
primecount+=1
if primecount==num-2:
return True
num=int(input("Enter Number: "))
for x in range(2,num+1):
if num%x==0 and prime(x)==True:
factorlist.append(x)
else:
continue
print("The largest prime factor of {} is {}".format(num,factorlist[-1]))
It's been 18 minutes now and still no result...