Q31. Write a code To check friendly pair

Program To Check Friendly Pair : This section focuses on Friendly Pair algorithm and program. The programs should be practiced to improve the coding skills required for various interviews (campus interviews, walk-in interviews), coding rounds etc.

Abundancy Pair : An Abundancy Pair is a number for which the sum of its proper divisors is greater than the number itself.
Friendly Pair : Two numbers are said to be friendly pairs if they have common abundancy index.
Given an number m and n and our task is to find Abundancy index of both the number and then need to check if they have common abundancy index or not.

For Example :-

Input : m= 28, n = 6
Output : Yes, The number is Friendly Pair
Explanation : As we can see that input number m = 28 and n = 6. The proper divisors of 6 is 1, 2, 3, 6 and proper divisors of 28 is 1, 2, 4, 7, 14, 28. The sum of proper divisors is 1 + 2 + 3 + 6 = 12 and 1 + 2 + 4 + 7 + 14 + 28 = 56. Abundancy index of 6 and 28 are 2. So they are friendly pair.

 Algorithm For Check Friendly Pair

START
Step 1 : Initilize numbers m and n.
Step 2 : Initialize two variables, sum1 and sum 2 with zero
Step 3 : Assign sum 1 with the sum of all the divisors of number m
Step 4 : Assign sum 2 with the sum of all the divisors of number n
Step 5 : If (sum 1==number1) and (sum 2==number 2), then print, “Friendly Numbers”
Step 6 : Else print “Not Friendly Numbers”
Stop

Code For Check Friendly Pair

Output

Yes, The number is Friendly Pair