Amicable series :-

Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper divisors of 6 are 1, 2, and 3.) so as series.

<br />#include<iostream>
#include<conio.h>
using namespace std;
int factor(int a)
{
int c=0;
for(int i=1;i<=a/2;i++)
if(a%i==0)c+=i;
return c;
}

int main()
{
int p=0,k,temp;
cout<<" Amicable Chain Till 1 Million :-"<<endl<<endl;
for(int i=2;i<1000000;i++)
{
k=0;
temp=factor(i);
if(temp==1)continue;
while(temp!=i)
{
k++;
if(k==10||temp==1)
break;
temp=factor(temp);
}
if(i==temp)
{
p++;
cout<<endl<<p<<".\t"<<i<<"->";
temp=factor(i);
while(temp!=i)
{
cout<<temp<<"->";
temp=factor(temp);
}
cout<<i;
}
}
getch();
}
//by tetra s.

Output :-
Untitled

Leave a comment