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;
    }
  • 相关阅读:
    洛谷 P2062 分队问题
    CentOS6.8安装GitLab
    restful service+jersey架构
    安装好VMware后,启动CentOS时失败
    开发文档模板
    Java内存模型
    虚拟机字节码执行引擎之方法调用
    虚拟机字节码执行引擎之运行时栈帧结构
    虚拟机类加载机制之类加载器
    虚拟机类加载机制之类的加载过程
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2925093.html
Copyright © 2011-2022 走看看