Given an even number n>2, find prime numbers, whose sum is n
maybe can star something how
for (int i = 2; i < n; i++)
{
if (IsPrime(i) && IsPrime(n - i))
break;
Given an even number n>2, find prime numbers, whose sum is n
maybe can star something how
for (int i = 2; i < n; i++)
{
if (IsPrime(i) && IsPrime(n - i))
break;
?
Interesting, but the statement is incomplete. How many prime numbers? 2? 3? Any number? Can the prime numbers repeat? Example: 26 = 13 + 13 (the prime 13 is repeating).
Well 3 doesn't have two prime numbers that add up to it (1 is not prime.) Is this case (of no solution) handled? Also, I would assume non-unique primes unless otherwise specified.
To figure out this algorithm, you can work out a few examples by hand. See how "you" would do it. Follow your steps carefully, and think about all exceptional cases (like 3.)
Please try.
You already have an algorithm. ¿what is the problem?
1 2 3 4 5
int golbach(int n){ //returns the minimum prime that satisfaces the golbach conjeture. n is even
for (int i = 2; i < n; i++)
if (IsPrime(i) && IsPrime(n - i))
return /*the prime*/;
}