def abundant_numbers(): numbers = [] for i in xrange(12,28123): divisors = get_divisors(i, True) sum_of_divisors = sum(divisors) if sum_of_divisors > i: numbers.append(i) return numbers
from common import get_divisors if __name__ == "__main__": print(get_divisors(220), get_divisors(284)) print(sum(get_divisors(220)), sum(get_divisors(284))) n = 10000 result = set() d = {} for i in range(1, n): d[i] = sum(get_divisors(i)) for i in range(1, n): if d[i] != i and d[i] < n and d[d[i]] == i: result.add(i) result.add(d[i]) print(sum(result))
from common import sum, get_divisors upper_limit = 10000 amicable = [] for x in xrange(1, upper_limit): d = sum(get_divisors(x)) if d != 0 and sum(get_divisors(d)) == x: if x != d: if x not in amicable: amicable.append(x) if d not in amicable: amicable.append(d) print amicable print sum(amicable)
from common import get_divisors upper_limit = 28123 abundant = [] total = 1 for x in xrange(2, upper_limit): if sum(get_divisors(x)) >= x: abundant.append(x) for y in abundant: if x-y in abundant: total += x break print total
from common import get_divisors def can_two_sum(numbers, n): i = 0 j = len(numbers) - 1 while i <= j: if numbers[i] + numbers[j] == n: return True elif numbers[i] + numbers[j] > n: j -= 1 else: i += 1 return False if __name__ == "__main__": n = 28123 abundant_number = [i for i in range(1, n + 1) if sum(get_divisors(i)) > i] print(abundant_number) print( sum([ i for i in range(1, n + 1) if not can_two_sum(abundant_number, i) ]))