# amicable numbers

• 11-06-2001
Zeeshan
amicable numbers
Hi guys,

I've been trying to solve this problem but it does work. Plz, help me with it's algorithm...

------------------------------------------------------------------------------
A pair of numbers is said to be amicable if the sum of some divisors of each of the numbers (excluding the number itself) is equal to the other number. For e.g., the numbers 1184 and 1210 are amicable since :

The divisors of 1184 are 592, 296, 148, 74, 37, 32, 16, 8, 4, 2, 1 whose sum is 1210

The divisors of 1210 are 605, 242, 121, 110, 55, 22, 11, 10, 5, 2, 1 whose sum is 1184

Plz note that all possible divisors may not b considered for making up the sum. FOR E.G. in the case of 12 & 16, the divisors of 12 are 1,2,3,4,6 whose sum is 16. Moreover the divisors of 16 are 1,2,4,8 of which the sum of 4 and 8 alone gives 12 (1,2 need not be considered). Hence amicability b/w two numbers exists if any m divisors out of the possible n divisors add up to the other number (in each case)..

--------------------------
I know this is a bit big....But, any try would be highly appreciated....Thanx a whole lot in advance...
• 11-06-2001
guest
Here's a shot at it.

obtain two numbers;
declare two flags to indicate equality of sum of divisors.
declare two int arrays to hold the divisors of the two numbers;
use a loop with given number % loop index = 0 to determine all divisors of given number;
repeat for second number;
use a loop to add each int in first array to one another one index at a time, if at any time the sum equals the second number you change one flag indicating the equality was found.
repeat loop for second numbers divisor checking for equality with the first number;
if both number's divisors added up to the other number at some point during the addition process then the two numbers are amicable.

shouldn't be too difficult to write the code--four loops, two flags, two ints, two int arrays.
• 11-06-2001
Korn1699
you could also use a class similar to the one I made for prime numbers and just modify it slightly. if you need that code or want it PM me
• 11-07-2001
Zeeshan
"guest", i can easily apply your method, but the problem is that as i have mentioned before ...

Quote:

Plz note that all possible divisors may not b considered for making up the sum.

the divisors of 16 are 1,2,4,8 of which the sum of 4 and 8 alone gives 12 (1,2 need not be considered). Hence amicability b/w two numbers exists if any m divisors out of the possible n divisors add up to the other number (in each case)..
Hence, the problem is not in taking the sum of all the divisors, but in taking the sum of some of the divisors...which means that i'll have to check out all possible COMBINATIONS of the divisors.

still, thanx 4 ur help...