Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and in all of mathematics. It states:

Every even integer greater than 2 can be expressed as the sum of two primes.
The conjecture has been shown to hold up through 4 × 1018 and is generally assumed to be true, but remains unproven despite considerable effort.

I make the project in C to prove his conjecture but I have missed a little detail. The program prints all the possible numbers that can create an N number.

Eg for number 14 the ouput prints

C
3 11
7 7


where the first number called p1 and the second one is p2 in my code.
I just want to keep the number with the smallest p1 not all the numbers.

I though to store p1 and p2 to a 2d array but that's how I created the program and I don't want to start over. How can I fix it?

The code is the following:
C
#include<stdio.h>
#include<math.h>
int primecheck(long int x);

int main()
{
  long int a,p1,p2;
  int i,j,k;
  
  FILE *input =  fopen("goldbach.in","r");
  fscanf(input,"%ld",&a);
  fclose(input);
  
  FILE *output = fopen("goldbach.out","w+");

  if ((a%2)==1)
  {
    return 1;
  }
  
  for (p1=2;p1<a;++p1)
  {
    for (p2=2;p2<a;++p2)
    {
     j=primecheck(p1),k=primecheck(p2);
       if ((j==0) && (k==0) && (p1+p2==a) && (p1<=p2))
		fprintf(output,"%ld %ld\n",p1,p2);
        
  }
  }
 fclose(output);
}

int primecheck(long int x)
{
long int i=2;
while (i<x)
{
if ((x%i)==0)
break;
++i;
}
if (i==x)
return(0);
else
return(1);
}
Posted
Updated 21-Dec-14 4:31am
v3
Comments
[no name] 21-Dec-14 20:41pm    
'A computer program can never be a mathematical proof' - my conjecture. Aside - How can you prove the program is bug free? Indeed you may disprove the Goldbach conjecture in this way but never prove it. I would suggest your effort is about 1% 'finished' and it will remain that way for eternity.
Sergey Alexandrovich Kryukov 21-Dec-14 22:37pm    
Not true. There are programs which could build and demonstrate 100% strict proof. For example, this way the well-known problem of 5 colors has been solved. You could say that a proof for several examples from an infinite set (the conjectures says "Every even integer greater than 2 can be expressed as the sum of two primes", important part is "every"; please see my answer).

I also cannot agree with your estimate "is about 1% 'finished'". In fact, OP's solution completeness can be expressed by some negative number; that is, it is worse than nothing at all. Wrong understanding of basic things is always much worse of total lack of knowledge.

—SA
[no name] 21-Dec-14 23:42pm    
Interesting. Yes it's true: http://en.wikipedia.org/wiki/Computer-assisted_proof and http://en.wikipedia.org/wiki/Five_color_theorem. I take your point and may improve my conjecture 'A computer program may prove a theorem requiring a finite number of solutions'.
There are still the philosophical issues especially for large calculations.
Sergey Alexandrovich Kryukov 21-Dec-14 23:56pm    
Sure, but such issues is a part of the fundamental of mathematics as well. It's a very interesting topic.
—SA

1 solution

The whole idea makes no sense from the very beginning. You are not even trying "to prove his conjecture".
Goldbach's conjecture states:

Every even integer greater than 2 can be expressed as the sum of two primes.
The key word here is "every". I hope there is no a need to explain anything else.

If you merely want to factorize any number and than see how many factors are there for each given number (even or odd), this is quite a trivial problem. I have no idea what advice would you possibly need. Just create a table of prime numbers (grow it accordingly if your test number is bigger than the biggest prime number you obtained) and try to divide your given test number by all the prime number from your set. The '%' operator returning zero should indicate that you can do a division without reminder. And use the debugger as you go.

—SA
 
Share this answer
 
v2
Comments
George Jonsson 21-Dec-14 22:17pm    
It is trivial to code, but a pain in the ass to wait for the answer. :)
+5
Sergey Alexandrovich Kryukov 21-Dec-14 22:32pm    
Thank you, George.
Anyway, I think it would be inappropriate to develop a ready-to-use solution for an inquirer who did not even try to do anything reasonable. GeorgeGkas can use the basic idea I describe and develop a factorization method, but why? :-)

—SA
Maciej Los 22-Dec-14 13:52pm    
+5
Sergey Alexandrovich Kryukov 22-Dec-14 14:04pm    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900