from amicable_numbers import d_n from itertools import combinations # lower limit is 20161 if __name__ == "__main__": abundants = set([ x for x in range(0, 47) if d_n(x) > x ]) odds_under_945 = set([ x for x in range(0, 945) if x % 2 == 1 ]) evens_under_945 = set([ x for x in range(0, 945) if x % 2 == 0 ]) sums_of_abundants = sorted(set([ sum(x) for x in combinations(abundants,2) if sum(x) < 945])) #numbers_under_945 = odds_under_945.union(evens_under_945.difference(sums_of_abundants)) #print numbers_under_945 even_maybe_not_sums_of_non_abundant = set([ x for x in range(0,47) if x % 2 == 0 ]) even_sum_of_non_abundants = even_maybe_not_sums_of_non_abundant.difference(sums_of_abundants) print sorted(even_sum_of_non_abundants) odds_over_945 = set([ x for x in range(945, 20162) if x % 2 == 1]) print len(odds_over_945) print sorted(set([x for x in range(0,20161) if d_n(x) == x ]))
def is_abundant(n): return True if d_n(n) > n else False
from amicable_numbers import d_n from itertools import combinations # lower limit is 20161 def sums(abundant_list): combos = combinations(abundant_list + abundant_list, 2) #print list(combos) return [ sum(x) for x in combos if sum(x) < 28123 ] if __name__ == "__main__": #abundants_to_945 = [ x for x in range(0,945) if d_n(x) > x ] # all evens above 46 are abundunt sums, evens under 46 may or maybe not abundant # all odds below 957 are not abundant sums, for the reason that the smallest odd abundant is 945, # thus the smallest odd sum of 2 abundants must be 957 (945 + 12) # odds above 957 and before 20161 maybe sums of abundants # any number below 24 are non-abundant sums all_abundants = [ x for x in range(0,28123) if d_n(x) > x ] sums_of_abundants = set(sums(all_abundants)) non_abundant_sums = set(range(0,28123)).difference(sums_of_abundants) print len(non_abundant_sums) print sum(non_abundant_sums)