哥德巴赫在C中的猜想(99%已完成) [英] Goldbach's conjecture in C (99% Finished)

查看:103
本文介绍了哥德巴赫在C中的猜想(99%已完成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哥德巴赫猜想是数论和所有数学中最古老,最着名的未解决问题之一。它声明:



每个大于2的偶数整数都可以表示为两个素数之和。

猜想已被证明为通过4×1018并且通常被认为是真实的,但是尽管付出相当大的努力仍未得到证实。



我在C中制作项目以证明他的猜想但是我错过了一点点细节。该程序打印所有可以创建N编号的数字。



例如14号输出打印



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

3 11
7 7





其中第一个号码叫 p1 ,第二个号码是我的代码中的 p2

我只是想要保留最小 p1 的数字而不是所有数字。



我要存储 p1 p2 到2d阵列,但这就是我创建程序的方式,我不想重新开始。我该如何解决?



代码如下:



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:

#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);
}

推荐答案

整个想法从一开始就毫无意义。 你甚至没有尝试证明他的猜想。

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



Every偶数大于2的整数可以表示为两个素数之和。


Every even integer greater than 2 can be expressed as the sum of two primes.

这里的关键词是每个。我希望没有必要解释其他任何事情。



如果你只想分解任何数字而不是看每个给定数字有多少因素(甚至或者奇怪),这是一个相当微不足道的问题。我不知道你可能需要什么建议。只需创建一个素数表(如果您的测试数大于您获得的最大素数,则相应地增长)并尝试将您给定的测试数除以您所设定的所有素数。返回零的'%'运算符应表示您可以在没有提醒的情况下进行除法。并随时使用调试器。



-SA

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


这篇关于哥德巴赫在C中的猜想(99%已完成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆