Positively Described Numbers - Part 1

Two numbers are "amicable" if the sum of the proper factors of one number is equal to the other number. The first pair of "amicable" numbers is 220 220 and 284. 284. What is the sum of the numbers that make the second pair of "amicable" numbers?

Details and Assumptions \textbf{Details and Assumptions}

The proper factors of a number are the positive factors of the number that are not equal to the number itself. For example, the proper factors of 12 12 are 1 , 1, 2 , 2, 3 , 3, 4 , 4, and 6. 6.

The proper factors of 220 220 are 1 , 1, 2 , 2, 4 , 4, 5 , 5, 10 , 10, 11 , 11, 20 , 20, 22 , 22, 44 , 44, 55 , 55, and 110. 110. The factors of 284 284 are 1 , 1, 2 , 2, 4 , 4, 71 , 71, and 142. 142. The numbers 220 220 and 284 284 are "amicable" because 1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284 1+2+4+5+10+11+20+22+44+55+110=284 and 1 + 2 + 4 + 71 + 142 = 220. 1+2+4+71+142=220.


The answer is 2394.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

7 solutions

Thaddeus Abiy
Mar 2, 2014

Python:

'Prints first five pairs'
def sum_divisors(n):
    s = 0
    for i in range(1,n):
        if n % i == 0: s += i
    return s

n , Count = 1 , 0
while Count <= 5:
    n += 1
    Val = sum_divisors(n)    
    if n == sum_divisors(sum_divisors(n)):
        print Count,n,Val,n+Val
        Count += 1

Python all the way! ;)

Thomas Luo - 7 years, 3 months ago
Karan Siwach
Oct 30, 2015

include<stdio.h>

include<math.h>

int main()

{

int i,j,m,n;

for(i=285;i<=1800;i++)
{
     int s1=0,s2=0,k=sqrt(i);
        for(j=2;j<=k;j++)
        {
            if(i%j==0) {s1=s1+j+i/j;}}
            s1+=1;
            int l=sqrt(s1);
            for(m=2;m<=l;m++)
            {
                if(s1%m==0){ s2=s2+m+s1/m;}

            } if(s2+1==i && s1!=i) {printf("%d\n",i+s1);
            return 0;}
        }

return 0;

}

Mayssara Moëtez
Apr 16, 2014

My Code in C:

  main(){int i,j,k, sum1=0, sum3=0, sum2=0;
 for(j=285; j<2000; j++)
   {  for(i=1; i<j; i++)
   {  
       if(j%i==0)
          sum1=sum1+i;
   }
    if(sum1!=j) 
    {
   for(k=1; k<sum1; k++)
   {  
       if(sum1%k==0)
          sum2=sum2+k;
   }
    }  
   if(sum2==j)
   {
     sum3=sum1+sum2;
     printf("s3=%d\n", sum3);
     break;  
   }    
    sum1=0;
    sum2=0;   
   }

}

Vaibhav Jain
Apr 12, 2014

Answere in Bacis C language:-

include<stdio.h>

include<stdlib.h>

int profac(int a){

int i,sum=0;

    for(i=1;i<=a/2;i++){

        if(a%i==0){

            //printf("a factor is %d\n",i);

            sum+=i;

        }

    }

    //printf("total sum of proper factor of %d is :-%d\n",a,sum);

    return sum;

} void main(){

int a=7,b;

int flag=1;

while(flag){

    b=profac(a);

    if (a==profac(b) && a!=b && (a!=220&&a!=284)){

        flag=0;

    }

    a+=1;

}

printf("AMICABLE numbers are %d and %d\n",a-1,b);

}

Sanjay Kamath
Apr 9, 2014

Here is my code in C#

        Here is a subroutine to be called for each number, say 1 to 2000

        private void GetFactorDetails(double num, ref double numsum)
       {
            //Positively Described Numbers - Part 1
        double n = num;
        double j = 2;
        double k = 0;
        double fcount = 1;
        ArrayList ar = new ArrayList();

        while (j < n)
        {
            k = (n % j);

            if (n != j)
            {
                if ((int)k == 0)
                {
                    fcount += j; j++; numsum = fcount; continue;

                }
                else
                {
                    j++; continue; 
                }
            }


            n++;
            fcount = 0;
            numsum = 0;
            if ((int)n == 1000) break;
        }//loop

    }

    Here is the calling routine.

         ArrayList ar = new ArrayList();


        double snum = 0;
        double tnum = 0;
        for (int jj = 1; jj < 2000; jj++)
        {

            GetFactorDetails(jj, ref snum);
            GetFactorDetails(snum, ref tnum);

            if ((jj == tnum) && (jj != snum))
            {
                if (!(ar.Contains(jj.ToString())))
                {
                    ar.Add(jj.ToString());
                }

                if (!(ar.Contains(snum.ToString())))
                {
                    ar.Add(snum.ToString());
                }
            }

        }

        for (int jk = 0; jk < ar.Count; jk++)
        {
            MessageBox.Show(ar[jk].ToString());
        }

import java.io.*; class hwe {

int r(int x) { int sum=0; for(int i=1;i<x;i++) { if(x%i==0) sum=sum+i; } return sum; } void am(int n) { for(int i=1;i<=n;i++) { int s1=r(i); int s2=r(s1); if(s2==i && s1>s2 && s2<=n) System.out.println(i+" "+s1); } } } here,void r function is used to generate the sum of proper factors of a number, s1 to find out the sum of proper factors of every number>=1 but<n and s2 to generate the sum of proper factors of s1

Joji Thomas
Mar 1, 2014

check wikipedia

That is definitely NOT how you solve this problem. That is cheating.

Trevor B. - 7 years, 3 months ago

Log in to reply

I checked wikipedia as well because I was confused; my code gave "amicable" numbers much lower than 220 and 284, such as 6 and 25: 1+2+3=1+5 -- the sum of the proper factors of 6 is equal to the sum of the proper factors of 25.

Turns out the first sentence of the question mislead me (and then I didn't read Details and Assumptions closely enough): it should say something like "Two numbers are "amicable" if the sum of the proper factors of one number is equal to the other number, and vice versa". Can you fix?

Casey McNamara - 6 years, 10 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...