Skip to content

Instantly share code, notes, and snippets.

@tomtheisen
Last active December 20, 2015 20:58
Show Gist options
  • Save tomtheisen/6193738 to your computer and use it in GitHub Desktop.
Save tomtheisen/6193738 to your computer and use it in GitHub Desktop.
Goldbach
void Main() {
for (BigInteger e = 4; IsSumOfTwoPrimes(e); e += 2);
}
bool IsPrime(BigInteger n) {
for (BigInteger f = 2; f * f <= n; f++) {
if (n % f == 0) return false;
}
return true;
}
bool IsSumOfTwoPrimes(BigInteger p) {
for (BigInteger a = 2; a <= p / 2; a++) {
if (IsPrime(a) && IsPrime(p - a)) return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment