I'm working on Project Euler, problem 3. The problem is:
"The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?"
In answering this question, I'm breaking down the task to first find all prime numbers < x (in reverse). Why does the following code not seem to work, I'm not sure if it is the logic or incorrect use of operator.
#A function to find prime numbers under n
def find_prime(n):
for i in reversed(xrange(2, n)):
if (n % i) != 0:
print i
find_prime(n)
In testing, I also built a prime number checker for fun, so I have tested somewhat.
def prime_checker(n):
if n > 2:
for i in range (2,n):
if (n % i) == 0:
print "%s is not a prime number" % (n)
break
else:
print "%s is a prime number" % (n)
Can anyone help me understand what I'm doing wrong with the find_prime() function before I move on to the next step that I will use to solve the problem?