def problem_23(): start_num = 3 factor_sums = [reduce(operator.add, utils.get_divizors(x, True)) for x in xrange(start_num, 28123)] ab_set = set([i + start_num for i,f_sum in enumerate(factor_sums) if f_sum > i + 3]) ab_sums = set(reduce(operator.add, x) for x in itertools.combinations(ab_set, 2)) ab_sums = ab_sums.union(set([x*2 for x in ab_set])) answers = set(xrange(28124)).difference(ab_sums) return reduce(operator.add, answers)
def problem_12(): def get_natural_num_sum(n): return (n**2 + n)/2 n = 1 while True: val = len(utils.get_divizors(get_natural_num_sum(n))) if val > 500: return get_natural_num_sum(n) n += 1
def problem_12(): def get_natural_num_sum(n): return (n**2 + n) / 2 n = 1 while True: val = len(utils.get_divizors(get_natural_num_sum(n))) if val > 500: return get_natural_num_sum(n) n += 1
def problem_23(): start_num = 3 factor_sums = [ reduce(operator.add, utils.get_divizors(x, True)) for x in xrange(start_num, 28123) ] ab_set = set([ i + start_num for i, f_sum in enumerate(factor_sums) if f_sum > i + 3 ]) ab_sums = set( reduce(operator.add, x) for x in itertools.combinations(ab_set, 2)) ab_sums = ab_sums.union(set([x * 2 for x in ab_set])) answers = set(xrange(28124)).difference(ab_sums) return reduce(operator.add, answers)
def problem_21(): start_num = 3 factors = [utils.get_divizors(x, True) for x in xrange(start_num, 10000)] factor_sum = [reduce(operator.add, factor) for factor in factors] # padd to make indexing easier for i in range(start_num): factor_sum.insert(0, 0) amicables = set() for indx in xrange(start_num, 10000): if factor_sum[indx] > 9999 or factor_sum[indx] < 0: continue if indx == factor_sum[factor_sum[indx]] and indx != factor_sum[indx]: amicables.update([indx, factor_sum[factor_sum[indx]]]) return reduce(operator.add, amicables)