21.py 380 B

123456789101112131415161718192021
  1. from math import sqrt
  2. def d(x):
  3. """Returns sum of divisors of given integer"""
  4. divList = []
  5. y = 1
  6. while y <= sqrt(x):
  7. if x % y == 0:
  8. divList.append(y)
  9. divList.append(int(x / y))
  10. y += 1
  11. divList.remove(x)
  12. return sum(divList)
  13. amicablesum = 0
  14. for a in range(1,10000):
  15. b = d(a)
  16. if d(a) == b and d(b) == a and b != 1 and a != b:
  17. amicablesum += a
  18. print amicablesum