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
#include<iostream>
#include<cmath>
using namespace std;
int prime[800000];
int isprime(int a)//判断是否是素数
{
int i;
for (i=2;i<=sqrt(a*1.0)+0.5;i++)
if(a%i==0)
return 0;
return 1;
}
void prime_b()//打素数表
{
int i;
for(i=2;i<=32768;i++)
if(isprime(i))//i是素数记为1
prime[i]=1;
else //不是记为0
prime[i]=0;
}
int main()
{
int n,p,k; prime_b(); while(cin>>n&&n)
{
k=0;
if(prime[n-2])//和2组和的数
k++;
for(p=3;p<=n/2;p+=2)
if(prime[p]&&prime[n-p])
k++;
cout<<k<<endl;
}
}

hdu1397(素数组和成偶数的个数 用 标记法)的更多相关文章

  1. c语言实践 统计输入的一串正整数里面奇数和偶数的个数

    怎么考虑这个问题. 首先先确定肯定是需要一个变量保存输入的数据的,我们叫它input,最后结果要的是个数,所以需要另外两个变量来保存奇数的个数和偶数的个数. int input int countJ ...

  2. 代码实现:判断101-200之间有多少个素数(质数),并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。

    package com.loaderman.Coding; /* 判断101-200之间有多少个素数(质数),并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能 ...

  3. hdu 2098 分拆素数和(一个偶数拆分成两个不同素数和 拆法数量)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2098 分拆素数和 Time Limit: 1000/1000 MS (Java/Others)     ...

  4. LightOJ1336 Sigma Function(约数和为偶数的个数)

    Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  5. 洛谷 P1865 A % B Problem[筛素数/前缀和思想/区间质数个数]

    题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Cros ...

  6. 剑指offer21----数组中奇数偶数

    题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 基本实现 如果不考虑时间复杂度,最简单的思路应该是从头扫描这个数组,每 ...

  7. 66.Subarray Sum Equals K(子数组和为K的个数)

    Level:   Medium 题目描述: Given an array of integers and an integer k, you need to find the total number ...

  8. :判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。

    package C; public class Sushu { public static void main(String[] args) { int sum=0; for (int i = 101 ...

  9. Java--数组转成list,list转数组

    数组转成list: 方法一: String[] userid = {"aa","bb","cc"}; List<String> ...

随机推荐

  1. Noip2008提高组总结

    Noip2008前三题是基础题,仔细一些都是可以AC的,第四题的证明很巧妙,但是看懂后代码其实很简单,感觉在这些大家都不屑去做的简单题中又学到了不少,四道题代码基本都是十几二十行就够了,渐渐感觉到,比 ...

  2. Hope

    透过希望的窗棂,在阴霾的罅隙里也可以寻找阳光,看到未来的春暖花开. ——forever97

  3. JAVA GUI学习 - JFileChooser文件选择器组件学习:未包括JFileChooser系统类学习

    public class JFileChooserKnow { /** * @param args */ public static void main(String[] args) { // TOD ...

  4. Flex TextInput的restrict属性应用

    1,<mx:TextInput id="test_ti" width="160" maxChars="20" restrict=&qu ...

  5. linux内核源码阅读之facebook硬盘加速利器flashcache

    从来没有写过源码阅读,这种感觉越来越强烈,虽然劣于文笔,但还是下定决心认真写一回. 源代码下载请参见上一篇flashcache之我见 http://blog.csdn.net/liumangxiong ...

  6. (" use strict")Javascript 严格模式详解

    Javascript 严格模式详解 转载别人的博客内容,浏览了一遍,没有全部吸收,先保存一下链接 http://www.ruanyifeng.com/blog/2013/01/javascript_s ...

  7. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )

    完全背包.. --------------------------------------------------------------------------------------- #incl ...

  8. python学习之lambda匿名函数

    1 Python支持运行时使用“lambda”建立匿名函数(anonymous functions that are not bound to a name). python "lambda ...

  9. 入门前端之HTML

    本文内容: HTML概念 HTML元素 HTML属性 HTML标题 HTML段落 HTML格式化 HTML样式 HTML 链接 HTML 图像 HTML 表格 HTML 列表 HTML 块 HTML ...

  10. js正则表达式的使用

    正则表达式的常用字符:   符号 描述 /../ 代表一个模式的开始和结束 ^ 匹配字符串的开始 $ 匹配字符串的结束 \s 任何空白字符 \S 任何非空白字符 \d 匹配一个数字字符,等价于[1-9 ...