Created
November 27, 2011 02:28
-
-
Save jakedobkin/1396831 to your computer and use it in GitHub Desktop.
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
| #!/usr/local/bin/node | |
| // declare an array to hold abundants, and also one to hold sum of two abundants | |
| abundants = new Array(); | |
| sieve = new Array(); | |
| // set abundants[i] = true if i is abundant | |
| for (i=1;i<=28123;i++) | |
| { | |
| itemsum=0; | |
| for (j=1;j<i;j++) | |
| { | |
| if (i%j==0) | |
| { | |
| itemsum+=j; | |
| } | |
| } | |
| if (itemsum > i) | |
| { | |
| abundants[i] = true; | |
| } | |
| } | |
| // we want to add every abundant to every other abundant in our list | |
| // and then cross out every one of those sums as true in our sieve array | |
| for(l=1;l<=28123;l++) | |
| { | |
| if(abundants[l]==true) | |
| { | |
| for(m=1;m<=28123;m++) | |
| { | |
| if(abundants[m]==true) | |
| { | |
| sieve[l+m]=true; | |
| } | |
| } | |
| } | |
| } | |
| // now that we've completed that, we simply add all values in sieve that are still false | |
| totalsum = 0; | |
| for(n=1;n<=28123;n++) | |
| { | |
| if(sieve[n]!=true) | |
| { | |
| totalsum+=n; | |
| } | |
| } | |
| console.log(totalsum + "is total sum of all integers that are not sum of two abundant numbers"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment