Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wongsyrone/94c31841c93743042761acd0633419ee to your computer and use it in GitHub Desktop.
Save wongsyrone/94c31841c93743042761acd0633419ee to your computer and use it in GitHub Desktop.
find sum of all divisors
public int divisorSum(int n){
// n has no divisors other than itself
if(n == 1){
return n;
}
// Find and sum divisors:
int half = n/2;
int sum = n;
do {
if(n % half == 0){
sum += half;
}
} while( half-- > 1 );
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment