Created
October 7, 2011 13:40
-
-
Save amacdougall/1270302 to your computer and use it in GitHub Desktop.
Project Euler problem 3
This file contains 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
# target = 13195 | |
target = 600851475143 | |
sub_target = target | |
current_factor = 2 | |
prime_factors = [] | |
while sub_target > current_factor: | |
while sub_target % current_factor > 0: | |
current_factor += 1 | |
prime_factors.append(current_factor) | |
sub_target /= current_factor | |
print "Greatest prime factor of %d is %d" % (target, prime_factors[-1]) | |
print "All prime factors: %s" % ", ".join([str(n) for n in prime_factors]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This brute-force solution falls down once you bump the input up a couple of orders of magnitude.