Skip to content

Instantly share code, notes, and snippets.

@AnshulBasia
Created July 1, 2016 22:44
Show Gist options
  • Save AnshulBasia/fdbf389b82b1c359bb8dfe4f38e098c0 to your computer and use it in GitHub Desktop.
Save AnshulBasia/fdbf389b82b1c359bb8dfe4f38e098c0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
long long divisorsum(long long a)
{
long long ans=1;
for(int i=2;i<=pow(a,.5);i++)
{
if(a%i==0)
{
if(i==a/i)
{
ans+=i;
}
else
{
ans+=i+(a/i);
}
}
}
return ans;
}
int main() {
// your code goes here
long long sum=0;
long long a[10000];
for(long long i=0;i<10000;i++)
{
a[i]=divisorsum(i+1);
// cout<<a[i]<<endl;
}
cout<<a[219]<<endl;
for(long long j=0;j<10000;j++)
{
if(a[j]<10000){
if((j+1==a[a[j]-1])&&(j+1!=a[j]))
{
sum+=j+1+a[j];
cout<<j+1<<" "<<a[j]<<" "<<a[a[j]-1]<<endl;
}
}
}
cout<<sum/2;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment