Created
March 30, 2012 13:59
-
-
Save shieldsd/2251729 to your computer and use it in GitHub Desktop.
Project Euler #23
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
| from math import sqrt | |
| def divisors(n): | |
| for x in xrange(1, int(sqrt(n)) + 1): | |
| if n % x == 0: | |
| yield x | |
| if x != 1 and x * x != n: | |
| yield n / x | |
| abundants = set() | |
| def abundantsum(n): | |
| if sum(divisors(n)) > n: | |
| abundants.add(n) | |
| if not any((n - a in abundants) for a in abundants): | |
| return 0 | |
| return 1 | |
| print sum(n for n in range(1, 28124) if not abundantsum(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment