Thread: amicable numbers

  1. #1
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226

    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...

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    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.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    241
    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

  4. #4
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226
    "guest", i can easily apply your method, but the problem is that as i have mentioned before ...

    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...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 07:56 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM