Created
August 9, 2013 22:31
-
-
Save dmrz/6197845 to your computer and use it in GitHub Desktop.
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
import collections | |
CACHE = collections.defaultdict(set) | |
CACHE[1].add(1) | |
def divisors(n): | |
if not CACHE[n]: | |
d = n | |
while d >= 1: | |
n % d or CACHE[d] and CACHE[n].update(CACHE[d]) or CACHE[n].add(d) | |
d -= 1 | |
result = CACHE[n].copy() | |
if len(result) > 1: | |
result.remove(n) | |
return result | |
def divisors_sum(n): | |
return sum(divisors(n)) | |
def main(): | |
numbers = [] | |
n = 1 | |
while n < int(1e4): | |
number = divisors_sum(n) | |
if number != n and n == divisors_sum(number): | |
numbers.append(n) | |
n += 1 | |
return sum(numbers) | |
if __name__ == '__main__': | |
result = main() | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment