Skip to content

Instantly share code, notes, and snippets.

@amacdougall
Created October 7, 2011 13:40
Show Gist options
  • Save amacdougall/1270302 to your computer and use it in GitHub Desktop.
Save amacdougall/1270302 to your computer and use it in GitHub Desktop.
Project Euler problem 3
# 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])
@amacdougall
Copy link
Author

This brute-force solution falls down once you bump the input up a couple of orders of magnitude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment