You're given a number $$$n$$$ It may be prime or not, It's required from you to get 4 positive prime numbers at which their summition equals to $$$n$$$, and if this isn't possible, then state that (There's more that one test cast BTW).
My approach was to get all prime numbers form 2 to 10000000 using sieve theory only once, and to try assume 3 of these numbers and get every possible combination of 2's and 3's (Assuming that all prime numbers can be deduce from summition of these two) let these numbers are $$$x$$$, $$$y$$$ and $$$z$$$ and if there exist a fourth number at which this 4th number = n - x + y + z
and If it's positive and prime, then we found the answer otherwise this won't be possible.
If there's something wrong with my approach? If not there's the mistake in my code Link to the problem is here
Hi! I can help you. Sum of two even numbers is even (one number we can write like 2 * k1 and seconde one as 2 * k2, so and sum is even). Sum of two odd numbers is also even (one number we can write like 2 * k1 + 1 and seconde one as 2 * k2 + 1, so sum is 2 * (k1 + k2) + 2, which is equal to 2 * (k1 + k2 + 1). Sum of even and odd is odd. Keep in mind that 2 is only even prime number. N can be odd, if N — 2 * 3 is prime. (Use equations from before.). If is N even, we can divide it into two equal parts, for which we can find solution. I hope I have helped you. Edit: My bad.
You need to generate all the primes up to N using the sieve of Eratosthenes. (Only once)
You need to know what Goldbach conjecture is
Now to make the number even we need to choose the first two primes in such a way that the resultant number after removing this primes must be even
Now you have an even number and you need to express it as a sum of two primes.
Nice solution.
P.S: memset can't be used to fill an array of integers with values other than 0, -1.You can use fill.
I don't know, my idea is similar to you as I mentioned above, anyway thank you, I really appreciate your help =D