def main(): LIMIT = 10000 divisors_sum = {number: sum(integers.proper_divisors(number)) for number in range(2, LIMIT + 1)} amicable_numbers = [] for n1, n2 in itertools.product(divisors_sum, divisors_sum): # if the sum of proper divisors of n_1 is the same as n_2 and vice # versa, then n_1 is an amicable number. if divisors_sum[n1] == n2 and divisors_sum[n2] == n1 and n1 != n2: amicable_numbers.append(n1) answer = sum(amicable_numbers) return answer
def main(): # Lowest abundant number is 12 # Every number greater than 28123 can be written as the sum of two abundant # numbers so only need to check up to 28123. LOWERBOUND = 12 UPPERBOUND = 28123 abundant_numbers = [number for number in range(LOWERBOUND, UPPERBOUND + 1) if sum(integers.proper_divisors(number)) > number] # Get the cross product of abundant numbers so we can determine every # number less than 28123 that is a sum of two abundant numbers. cross_product = itertools.product(abundant_numbers, abundant_numbers) sum_of_abundants = set((sum(tup) for tup in cross_product if sum(tup) <= UPPERBOUND)) # Every number less than or equal to UPPERBOUND that is not a part of the # set sum_of_abundants is the set we need. not_sum_of_abundants = set(range(1, UPPERBOUND + 1)) - sum_of_abundants answer = sum(not_sum_of_abundants) return answer