#!/bin/python

#my solution to Project Euler - problem 3
#Leigh Hall / 30-may-14
#DON'T RUN THIS AS IT WILL RUN OUT OF MEMORY BEFORE IT DOES ANYTHING WORTHWHILE
#needs a rethink.

def isprime(n):
	for i in range (2,n/2):
		if n % i == 0:
			return 0
	return 1

def lpf(n):
	print "testing ", n
	x=n/3-1
	print "starting with ", x
	for i in range(x,2,-1):
		print "is ", i, " a factor?"
		if n % i == 0:
			print "yes, is it prime?"
			if isprime(i):
				return i

print lpf(600851475143)
#print lpf(13195)
#print isprime(29)

