24 lines
587 B
Python

def all_factor(num):
factors = [1]
sqrt = int(num ** 0.5)
if sqrt ** 2 == num:
factors.append(sqrt)
sqrt -= 1
for x in range(2, sqrt + 1):
if not (num % x):
factors += [x, num // x]
return factors
def count_amicable(begin, end):
total = 0
while begin < end:
factor_sum = sum(all_factor(begin))
if (sum(all_factor(factor_sum)) == begin) and (factor_sum != begin):
total += begin + factor_sum
begin = factor_sum
begin += 1
return total
print(count_amicable(200, 10000))