Skip to content

Instantly share code, notes, and snippets.

@benmmurphy
Last active December 16, 2015 05:09
Show Gist options
  • Save benmmurphy/5382629 to your computer and use it in GitHub Desktop.
Save benmmurphy/5382629 to your computer and use it in GitHub Desktop.
dual palindromic primes of n digits
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