Created
February 4, 2015 11:49
-
-
Save ssanin82/91664b3991145db592a3 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
private int sumOfFactorsPrime(int number, int[] primelist) { | |
int n = number; | |
int sum = 1; | |
int p = primelist[0]; | |
int j; | |
int i = 0; | |
while (p * p <= n && n > 1 && i < primelist.Length) { | |
p = primelist[i]; | |
i++; | |
if (n % p == 0) { | |
j = p * p; | |
n = n / p; | |
while (n % p == 0) { | |
j = j * p; | |
n = n / p; | |
} | |
sum = sum * (j - 1) / (p - 1); | |
} | |
} | |
//A prime factor larger than the square root remains | |
if (n > 1) { | |
sum *= n + 1; | |
} | |
return sum - number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment