Description

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. There can be many such numbers. 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 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
题目大意:

对于任何偶数n大于等于4,至少存在一个质数p1和p2这样

n = p1和p2

这个猜想尚未证明也不拒绝。没人知道是否这个猜想成立。然而,人们可以发现这样一双质数,如果有的话,对于给定的一个偶数。这里的问题是编写一个程序,报告所有成对的质数的数量满足条件给定的一个偶数的猜想。

给出一个偶数序列作为输入。可以有许多这样的数字。对应于每个数字,程序应该输出对上面提到的数量。注意,我们感兴趣的数量对本质上是不同的,因此你不应计数(p1,p2)和(p2,p1)分别作为两个不同的配对。

#include<iostream>
using namespace std;
bool aa(int b) //判断质数函数
{
for(int i=3;i*i<=b;i++)
{
if(b%i==0)return 0;
}
return 1;
} int main()
{
int a;
cin>>a;
while(a)
{
int q=0;
for(int j=3;j*2<=a;j+=2)//排除偶数,减少时间消耗
{
if(aa(j)&&aa(a-j))
q++;
}
cout<<q<<endl;
cin>>a;
} return 0;
}

  

poj-2909-哥德巴赫猜想的更多相关文章

  1. Goldbach's Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想

    题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i]  i这个数是不是素数  在线性筛后面加个装桶循环即可 #inc ...

  2. *CF2.D(哥德巴赫猜想)

    D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. C#实现哥德巴赫猜想

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Goet ...

  4. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  5. CF735D Taxes 哥德巴赫猜想\判定素数 \进一步猜想

    http://codeforces.com/problemset/problem/735/D 题意是..一个数n的贡献是它的最大的因子,这个因子不能等于它本身 然后呢..现在我们可以将n拆成任意个数的 ...

  6. Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想

    D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...

  7. Codeforces 735D:Taxes(哥德巴赫猜想)

    http://codeforces.com/problemset/problem/735/D 题意:给出一个n,这个n可以分解成 n = n1 + n2 + -- + nk,其中k可以取任意数.要使得 ...

  8. LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)

    http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...

  9. Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  10. 哥德巴赫猜想证明(C语言实现50以内的正偶数证明)

    <一>哥德巴赫猜想内容: 一个充分大的偶数(大于或等于6)可以分解为两个素数之和. <二>实现要点: 要点: 判断素数(质数):除了1和本身没有其他约数. 最小的质数:2 判断 ...

随机推荐

  1. Linux基础五

    Yum软件包管理 yum:基于rpm包构建的软件更新机制 自动解决软件包依赖关系 所有软件包由集中的yum软件仓库提供. [root@hydra桌面]#ls /misc/cd/repodata/ (r ...

  2. jqeury显示前几个,隐藏后几个,点击后隐藏前几个显示后几个

    <script type="text/javascript"> $(".ul li").each(function(){ if($(this).in ...

  3. ERROR 1045 (28000): Access denied for user xxx & ERROR 1449 (HY000): The user specified as a definer xxx does not exists

    今天在一个修改过权限的MySQL数据库遇到了"ERROR 1045 (28000): Access denied for user 'xxx'@'xxx.xxx.xxx.xxx' (usin ...

  4. 2.5 非透明PCI桥

    PCI桥规范定义了透明桥的实现规则,本篇在第2.3.1节中详细介绍了这种桥片.通过透明桥,处理器系统可以以HOST主桥为根节点,建立一颗PCI总线树,在这个树上的PCI设备共享同一个PCI总线域上的地 ...

  5. VS2005 添加lib 的方法

    应用程序使用外部库时需要进行加载,两种库的加载本质上都是一样:提供功能和功能的定义.vs2005 c++ 项目设置外部库方法如下:1. 添加编译所需要(依赖)的 lib 文件     在"项 ...

  6. 基于嵌入式操作系统VxWorks的多任务并发程序设计(1)――基本概念

    1引言 嵌入式系统定义义为:嵌入到对象体系中的专用计算机系统."嵌入性"."专用性"与"计算机系统"是嵌入式统的三个基本要素,对象系统则是指 ...

  7. HighCharts之2D堆条状图

    HighCharts之2D堆条状图 1.HighCharts之2D堆条状图源码 StackedBar.html: <!DOCTYPE html> <html> <head ...

  8. NetBeans导入项目jar路径错误解决办法

    NetBeans导入项目jar路径错误解决办法 1.NetBeans中导入项目jar路径出错,单击项目右键,选择"属性",找到"库" 2.找到错误jar,全部勾 ...

  9. R分词

    #用于下载安装rJava 和 Rwordseg,如果安装了就注释掉 install.packages("rJava") install.packages("Rwordse ...

  10. strcmp函数实现

    /* 功能:比较字符串s1和s2大小. 一般形式:int strcmp(字符串1,字符串2) 说明: 当s1<s2时,返回-1 当s1=s2时,返回 0 当s1>s2时,返回 1 即两个字 ...