Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save shohan4556/713980160fef3b07ee34 to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/713980160fef3b07ee34 to your computer and use it in GitHub Desktop.
Projecteuler 21 solution in C
/// Solved By Shohanur Rahaman
#include<stdio.h>
#include<math.h>
int sumofdiv(int n);
int main()
{
int i,j;
int n,count=0,div1=1,tmp=0,div2=0;
int sum=0;
n=1;
while(n<=10000){
int root=sqrt(n);
for(i=2;i<=root;i++){
if(n%i==0){
div1=div1+i;
if(i!=n/i)
div1=div1+(n/i);
}
}
tmp=sumofdiv(div1);
if(tmp==n && tmp!=div1){
sum=sum+div1;
printf("Div1 : %d Tmp: %d \n",div1,tmp);
}
div1=1;
n++;
}
printf("\n sum : %d\n",sum);
return 0;
}
int sumofdiv(int n)
{
int i,div=1;
int root=sqrt(n);
for(i=2;i<=root;i++){
if(n%i==0){
div=div+i;
if(i!=n/i){
div=div+n/i;
}
}
}
return div;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment