The prime factors of 13195 are 5, 7, 13 and 29. What is the largest
prime factor of the number 600851475143 ?
prime_list= #Begin with zero so that we can pop later without errors.
#Define a function that finds all the odd numbers in the range of a number
x+=1 #add one to the number because range does not include it
for i in range(x):
if i%2!=0: #If it cannot be evenly divided by two it is eliminated
odd_list.append(i) #Add it too the list
def findPrimes(number_to_test, list_of_odd_numbers_in_tested_number): # Pass in the prime number to test
for i in list_of_odd_numbers_in_tested_number:
if number_to_test % i==0:
number_to_test=number_to_test / i
#prime_list.pop(-2) #remove the old number so that we only have the biggest
print "This has no prime factors other than 1"
number_to_test=raw_input("What number would you like to find the greatest prime of?\n:")
#Convert the input to an integer
#Pass the number to the oddnumbers function
#Pass the return of the oddnumbers function to the findPrimes function
findPrimes(number_to_test , odds)
600851475143is big to discourage you to use brute-force.
oddNumbersfunction in going to put
600851475143 / 2numbers in
odd_list, that's a lot of memory.
you could use a generator to get the list of odds (not that it will help you):
odd_list = xrange(1, number+1, 2)
here are the concepts needed to deal with prime numbers:
if you are really stuck, then there are solutions already there: