zoukankan      html  css  js  c++  java
  • Goldbach's Conjecture(哥德巴赫猜想)

    Goldbach's Conjecture

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5277    Accepted Submission(s): 2022

    点我

    Problem Description
    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 (p1, p2) and (p2, p1) 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 2^15. 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
     1 #include <iostream>
     2 using namespace std;
     3 int a[32765];
     4 int isprime()
     5 {
     6     int i,k,x;
     7     for(i=2;i<32765;i++)
     8     {
     9         for(k=2;k<=i/2;k++)
    10         {
    11             if(i%k==0)
    12                 break;
    13         }
    14         if(k==i/2+1)
    15             a[i]=1;
    16         else
    17             a[i]=0;
    18     }
    19     return 0;
    20 }
    21 int main()
    22 {
    23     int x,i,j,count=0;
    24     isprime();
    25     while(cin>>x&&x)
    26     {
    27         count=0;
    28         for(i=j=x/2;i>=2;i--,j++)
    29         {
    30             if(a[i]&&a[j])
    31             {
    32                 count++;
    33             }
    34         }
    35         cout<<count<<endl;
    36     }
    37 }
     
  • 相关阅读:
    mysql的IFNULL()函数FLOOR(),ROUND()函数
    何时有个内连接何时用外连接
    Mybatis中什么时候应该声明jdbcType
    FFPEG 转码记录------解决了有流,但是没有码率和FPS?
    HLS播放权限测试记录
    Redis-benchmark测试Redis性能
    JavaScript基础知识之——Location 对象详解
    Redis基础知识之—— 缓存应用场景
    Redis基础知识之—— hset 和hsetnx 的区别
    SAGE入门:开源数学系统之集大成者
  • 原文地址:https://www.cnblogs.com/a1225234/p/4681245.html
Copyright © 2011-2022 走看看