### Need help on goldbachs conjecture

deleted
Last edited on
deleted
Last edited on
deleted
Last edited on
deleted
Last edited on
I didn't read your opening post carefully. So use your given function primecheck on every number from 2 to half of your even number N. When a prime number p is found, test if primecheck (N - p) returns true or not. Repeat this for all N from 1 to 10000.
Last edited on
deleted
Last edited on
My post above is the hint you need.
Last edited on
Ok ill try
deleted
Last edited on
Use k +=2 (since you are starting at k = 2), instead of k++ to speed it up.
Then, within that loop, put in another loop:

 ``123456789`` ``````(for int i = 2; i < k /2; i++) { if (primecheck (i) && primecheck (k-i)) { cout << i << " + " << k-i << " confirms GoldBach's conjecture for " << k << endl; break; } } cout << "Goldbach's conjecture is false! " << k << " is the first counterexample!" << endl; // this should never happen if you believe in the conjecture ``````

Last edited on
deleted
Last edited on
deleted
Last edited on
so, this is simple:
Find every prime, and add another prime to it.

This can be done easily by testing !X combinations of pprimes found.

`primecheck()` returns true for primes, so it's simply a matter of finding the primes, and checking each prime against each prime after it.

 ``1234567891011`` ``````//check each combination. for(unsigned long int x = 1; x <= 10000; x++) { for(unsigned long int y = (x + 1); ((y <= 10000) && primecheck(x); y++) { if(primecheck(y)) { cout<< x<< " + "<< y<< " = "<< (x + y)<< '\n'; } } }``````

You CAN NOT just do 5000. You have to check every combination of prime numbers, that's the whole point. If you really want to make it more efficient, put all the prime numbers into a vector or array. Then you can skip all the non-prime numbers on the sequential loops without any overhead at all.
Last edited on
You need another boolean flag to indicate whether to show "Goldbach's conjecture is false!" or not (bool nothingFound = true, set it to false when sum is found, display the above quote only if (nothingFound), reset it back to true before starting a new loop). To make it simple, just remove that line then. Then your above output is what you want.

But in case Goldbach's conjecture is false, your ideal solution should have that possible output (though you personally will never see it):
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include using namespace std; bool primecheck (int n) { int k=2; while(k<= sqrt(n) && n%k !=0) k++; return k>sqrt(n); } int main () { bool nothingFound = true; for (int k = 6; k<=10000; k+=2) { cout <
Last edited on
Topic archived. No new replies allowed.