zoukankan      html  css  js  c++  java
  • [解题报告]686 Goldbach's Conjecture (II)

      Goldbach's Conjecture (II) 

    Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2.


    This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.


    A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are interested in the number of essentially different pairs and therefore you should not count (p1p2) and (p2p1) separately as two different pairs.

    Input 

    An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 215. The end of the input is indicated by a number 0.

    Output 

    Each output line should contain an integer number. No other characters should appear in the output.

    Sample Input 

    6
    10
    12
    0
    

    Sample Output 

    1
    2
    1
    

    Miguel A. Revilla 
    1999-03-05
     
     
    依旧是建质数表
    #include<stdio.h>
    #include<math.h>
    int math[5200]={0};
    int num[32768]={0};
    int main()
    {
     int n,a,b,c,m=1;
     math[0]=2;
     for(a=3;a<32768;a=a+2)
      {
       int flag=0;
       for(b=0;math[b]<=sqrt(a);b++)
        {
         if(a%math[b]==0)
          {
           flag=1;
           break;
          }
        }
        if(flag==0)
         {
          math[m]=a;
          m++;
         }
      }
     for(a=1;a<m;a++)
      for(b=a;b<m;b++)
       {
         if(math[a]+math[b]>=32768) break;
         else num[math[a]+math[b]]++;
       }
     while(scanf("%d",&n)==1&&n!=0)
      printf("%d\n",(n==4)?1:num[n]);
     return 0;
    }
  • 相关阅读:
    大型网站架构之分布式消息队列【转】
    Jpa生成mysql注释,添加ODBC数据源导入数据到EA
    Spring boot框架项目,使用maven命令将配置文件打包到jar包外,项目运行读取jar外配置文件
    spring boot 整合 quartz 集群环境 实现 动态定时任务配置【原】
    关于博主
    [School Life] 骗你去努力
    [OI
    洛谷P4994【终于结束的起点】
    [OI系列]在考场千万不能犯的错误
    [OI
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2925093.html
Copyright © 2011-2022 走看看