1  /  1  页   1 跳转 查看:412

标题: 【验证哥德巴赫猜想】求助!!!

【验证哥德巴赫猜想】求助!!!

我下面这个程序是问题出现在运行后在验证哥德巴赫猜想中会出现很多的重复计算式,有些还没有全部显示出来!!
比如说验证  20 时,它会出现下面的结果:
                                                                    20=13+7;
                                                                    20=13+7;
                                                                    20=11+9
源程序如下:
    /* Note:Your choice is C IDE */
#define MAX 1024
#include "stdio.h"
#include "string.h"
int prime(int j,int p[])
{  int x,n=0,r,m;
    printf("\nPlease insert a even number(x>=6):");
  scanf("%d",&x);
  while(x%2!=0||x<6)
  {
    printf("The data is error!  Please enter again!\n");
    printf("And the number you insert must greatness of 6 !\n");
    scanf("%d",&x);
  }
  for(;j>0;j--)
      { n=x-p[j];
      if(n>0)
        {m=n/2;
          for(r=2;r<=m;r++)
        {if(n%r!=0&&p[j]>=n)
    {printf("%d= %d + %d\n",x,p[j],n);}
      else {break;}
        }
        }         
      } return 1;     
}
main()
{
  int i,h,k=0,p[MAX]={0},a[MAX]={0};
  int N;
    printf("\nPlease insert the Max data:");
    scanf("%d",&N);
    for(i=1;i<N;i++)a=i+1;        /*将所有候选数放入筛中*/
    for(i=0;i<N;i++)
    if(a!=0)
  {
    p[k]=a;        /*将最小数放入素数集合p中*/
  for(h=k;h<N;h++)
  if(a[h]%p[k]==0)a[h]=0;    /*将这个素数的倍数从筛中删去*/
    k++;
    }
i=0;
printf("Put out all primes:\n");
while(p!=0){printf("%5d",p);i++;}  /*打印出所有素数*/
prime(i,p);
}
[size=1.5]The  happier  you  are  about  yourself  and  your  life, the  healthier  you will  be !
引用
 

回复:【验证哥德巴赫猜想】求助!!!

哈哈……  我已经修改出来了! 
但是我想向高手们征求更好的解决办法! 
  快来参与其中吧!
最后编辑DBTreasure 最后编辑于 2008-05-03 17:07:42
[size=1.5]The  happier  you  are  about  yourself  and  your  life, the  healthier  you will  be !
引用
 
1  /  1  页   1 跳转

版权所有 畅游榕城  Discuz!NT  Sitemap

Powered by Cyrcbbs.com 
Processed in 0.265625 second(s) , 3 queries. 闽ICP备07046376号
返顶部