[2708 views]
Two numbers are said to be amicable numbers if the sum of the divisor of each number is equal to the other number. For example: 220 and 284, 1184 and 1210, 2620 and 2924, etc.
Let us consider the example of 220 and 284.
Divisors of 220: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
Sum of divisors: 1+2+4+5+10+11+20+22+44+55+110 = 284
Divisors of 284: 1, 2, 7, 71, 142
Sum of divisors: 1+2+7+71+142 = 220
Therefore, as 220 and 284 are the equal the sum of divisors of each other, they are an amicable number pair.
In this article, we will learn how to check whether two given numbers are an amicable pair or not, with the help of an algorithm and flowchart.
In this algorithm, we need to check whether two given numbers are amicable numbers or not. To do so, we need to find out all the divisors of each number and then find out the sum of those divisors separately. If the sum of divisors is equal to the other number, it is an amicable number pair.
We start the algorithm by taking the two numbers to be checked as user input. We store these numbers in two variables, say n1 and n2. We then initialize the sum of divisors of these numbers as 0, which will be used later. Now, we must find out the divisor of each of the two numbers and then find out the sum accordingly. To do so, we start a loop that runs from 1 to n1. In each iteration of this loop, we check whether n1 is divisible by the loop variable i or not. If it is divisible, then i is a divisor of n1. So, we add i to the sum of divisors of the first number, which was initialized earlier.
Once this loop terminates, we repeat the same process for n2. After we get both the sums, we check whether sum_n1 and sum_n2 are equal or not. If it is equal, the given pair is amicable. Else, it is not amicable. The appropriate message is displayed.