Last active
August 29, 2015 14:15
-
-
Save shohan4556/713980160fef3b07ee34 to your computer and use it in GitHub Desktop.
Projecteuler 21 solution in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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