Friendly Pairs, also known as Amicable Numbers, are two numbers that share the same abundance ratio. The abundance ratio of a number is the sum of its proper divisors divided by the number itself. If two numbers have the same abundance ratio, they are considered Friendly Pairs.
For example, 6 and 28 are Friendly Pairs because: Sum of divisors of 66=Sum of divisors of 2828\frac{\text{Sum of divisors of } 6}{6} = \frac{\text{Sum of divisors of } 28}{28}6Sum of divisors of 6=28Sum of divisors of 28
Proper divisors of a number are all its positive divisors except the number itself. For instance:
Since both 6 and 28 have the same ratio when their sum of proper divisors is divided by themselves, they are considered Friendly Pairs.
To determine if two numbers num1 and num2 are Friendly Pairs, the following condition must hold: ∑(Proper Divisors of num1)num1=∑(Proper Divisors of num2)num2\frac{\sum \text{(Proper Divisors of num1)}}{\text{num1}} = \frac{\sum \text{(Proper Divisors of num2)}}{\text{num2}}num1∑(Proper Divisors of num1)=num2∑(Proper Divisors of num2)
If this condition is met, the numbers are Friendly Pairs; otherwise, they are not.
Example 1:
Input:
CopyEdit6 28
Output:
nginxCopyEditFriendly Pair
Example 2:
Input:
CopyEdit8 25
Output:
mathematicaCopyEditNot Friendly Pair
num1 and num2.num1 and num2."Friendly Pair", otherwise, print "Not Friendly Pair".cCopyEdit#include <stdio.h>
// Function to calculate the sum of proper divisors of a number
int sumOfDivisors(int num) {
int sum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
return sum;
}
int main() {
int num1, num2;
// Input two numbers
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
// Compute the sum of divisors
int sum1 = sumOfDivisors(num1);
int sum2 = sumOfDivisors(num2);
// Compute abundance ratios
float ratio1 = (float)sum1 / num1;
float ratio2 = (float)sum2 / num2;
// Check if they are Friendly Pairs
if (ratio1 == ratio2) {
printf("Friendly Pair\n");
} else {
printf("Not Friendly Pair\n");
}
return 0;
}
sumOfDivisors(int num)1 to num/2.i, it is added to the sum.sumOfDivisors() function for both numbers.sumOfDivisors(num) runs in O(n/2) time, which simplifies to O(n).Input:
CopyEdit6 28
Output:
nginxCopyEditFriendly Pair
Explanation:
1 + 2 + 3 = 6.1 + 2 + 4 + 7 + 14 = 28.Input:
CopyEdit8 25
Output:
mathematicaCopyEditNot Friendly Pair
Explanation:
1 + 2 + 4 = 7.1 + 5 = 6.1 as their proper divisor, so they will never be Friendly Pairs.Advantages:
Disadvantages:
Friendly Pairs (Amicable Numbers) are two numbers that share the same abundance ratio. The program efficiently determines if two numbers are Friendly Pairs by computing the sum of their proper divisors and comparing their abundance ratios. This is a fundamental problem in number theory and helps in understanding the properties of divisors and number relationships.