Last active
December 16, 2015 05:09
-
-
Save benmmurphy/5382629 to your computer and use it in GitHub Desktop.
dual palindromic primes of n digits
This file contains 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
public static int count(int digits) { | |
if (digits % 2 == 0) { | |
return countEven(digits); | |
} else { | |
return countOdd(digits); | |
} | |
} | |
public static int countEven(int digits) { | |
// +1 -1 | |
return fun(digits / 2); | |
} | |
public static int countOdd(int digits) { | |
int roundDown = (digits) / 2; | |
return 2 * fun(roundDown) + roundDown; | |
} | |
public static int fun(int n) { | |
return (n * n * n - 3 * n * n + 8 * n + 6)/6; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment