Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import math
  2.  
  3. def amicable(n):
  4. def sum_factors(x):
  5. factors = 1
  6. total = 1
  7. for i in range(2, int(math.sqrt(x)) + 1):
  8. if(x%i == 0):
  9. total = total + i + x / i
  10. return total
  11.  
  12. not_amicable = True
  13. test_amicable = n+1
  14. while not_amicable:
  15. test_amicable_partner = sum_factors(test_amicable)
  16. print(str(test_amicable_partner), str(sum_factors(test_amicable_partner)), str(test_amicable))
  17. if(sum_factors(test_amicable_partner) == test_amicable and test_amicable != test_amicable_partner):
  18. not_amicable = False
  19. test_amicable = test_amicable+1
  20. return test_amicable
  21.  
  22. print (str(amicable(5)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement