Please help with task

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;

?
shadowmangb wrote:
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).
ok, my fault, the task complete is :

Given an even number n>2, find two prime numbers, whose sum is n
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.)
3 is not even, xP
But yeah, I think that that is Golbach's conjeture.

Your approach seems correct (quite inneficient thought) ¿what is the problem?
Lol, didn't see even numbers only.
somebody know how to write working code? :(
We probably do, but that defeats the objective of the exercise, which is: You do it.

We can help if something isn't working as expected, but we probably won't do the whole thing for you. You have to come up with an algorithm yourself.
Last edited on
like if n=348 primes are 11 and 337...?
yes there can be prime numbers 13+13=26
please help
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*/;
}
there need some addition to this code
Topic archived. No new replies allowed.