What are amicable numbers?
Amicable numbers or friendly numbers are a pair of numbers whose sum of proper divisors equals the other.
Implementation
Below is a program that checks whether or not two numbers form an amicable pair. Feel free to change num1 and num2 to check if a pair is amicable.
# A function that takes an integer and returns the sum of its proper divisors.# E.g. proper divisors of 8 are 1, 2 and 4 so the function will return# 7 (1 + 2 + 4) when 8 is given as inputdef sum_of_proper_divisors(num):divisor_sum = 0for i in range(1, num):if (num%i == 0):divisor_sum += ireturn divisor_sum# A function that takes two integers as input and returns true if the two# form an amicable pair and false if notdef form_amicable_pair(num1, num2):if (sum_of_proper_divisors(num1) == num2) and (sum_of_proper_divisors(num2) == num1):return Trueelse:return False# Two integers being testednum1 = 220num2 = 284if form_amicable_pair(num1, num2):print(str(num1)+" and "+str(num2)+" are amicable numbers!")else:print(str(num1)+" and "+str(num2)+" are not amicable numbers!")
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved