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 }
     
  • 相关阅读:
    WebForms UnobtrusiveValidationMode 须要“jquery”ScriptResourceMapping。
    用R进行微博分析的初步尝试
    使用Docker部署Gitlab
    怎样托管你的项目到github上具体教程
    Android Api Demos登顶之路(四十五)Loader--&gt;Cursor
    【C语言】推断一个数是否为2的n次方
    Akka并发编程——第五节:Actor模型(四)
    POJ2773 Happy 2006【容斥原理】
    作用域与生命周期
    C# string
  • 原文地址:https://www.cnblogs.com/a1225234/p/4681245.html
Copyright © 2011-2022 走看看