Created
March 27, 2012 20:12
-
-
Save a-r-d/2219877 to your computer and use it in GitHub Desktop.
project euler 3- not optimized
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#proj euler 3 | |
''' | |
The prime factors of 13195 are 5, 7, 13 and 29. | |
What is the largest prime factor of the number 600851475143 ? | |
''' | |
factorsList = [] | |
i = 2 | |
while i <= 600851475143 / 3:#maybe make it faster? | |
if 600851475143 % i == 0: | |
print i | |
factorsList.append(i) | |
i += 1 | |
#now we have all of its factors in a list. | |
print factorsList | |
primesList = [] | |
for factor in factorsList: | |
i = 2 #start @ 2 always | |
prime = True | |
while(i < factor): | |
if factor % i == 0: | |
print "factor", factor, "not prime, divisible by", i | |
prime = False | |
break | |
i += 1 | |
if prime == False: | |
primesList.append(factor) | |
# sort and display | |
primesSorted = sorted(primesList, reverse=True) | |
print "Largest prime factor is:", primesSorted[0] | |
print "hit enter to end" | |
inpt = input(">") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment