http://ac.jobdu.com/problem.php?cid=1040&pid=52

题目描述:

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.

输入:

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.

输出:

Each output line should contain an integer number. No other characters should appear in the output.

样例输入:
6
10
12
0
样例输出:
1
2
1
// 题目53:Goldbach's Conjecture.cpp: 主项目文件。#include "stdafx.h"
#include <cstdio>
#include <cstring>const int N=32770;
bool used[N];void selectPrime()
{memset(used,0,sizeof(used));used[0]=used[1]=true;for(int i=2;i<N;i++){if(!used[i]){for(int j=i+i;j<N;j+=i)used[j]=true;}}
}int gedebahe(int n)
{int cnt=0;for(int i=2;i<=n/2;i++){if(!used[i]){int j=n-i;if(!used[j])cnt++;}}return cnt;
}int main()
{int n;selectPrime();while(scanf("%d",&n)!=EOF&&n){int res=gedebahe(n);printf("%d\n",res);}return 0;
}

转载于:https://www.cnblogs.com/cjweffort/archive/2013/03/06/3374887.html

题目53:Goldbach's Conjecture相关推荐

  1. 题目1440:Goldbach's Conjecture(哥达巴赫猜想)

    题目链接:http://ac.jobdu.com/problem.php?pid=1440 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  2. 九度题目1440:Goldbach's Conjecture

    题目描述: Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least ...

  3. 【POJ - 2262】Goldbach's Conjecture (数论,哥德巴赫猜想,知识点结论)

    题干: In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in ...

  4. poj 2262 Goldbach's Conjecture——筛质数(水!)

    题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...

  5. Goldbach's Conjecture

    题目描述 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 4 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=11+3 ...

  6. Goldbach`s Conjecture(数论)素数筛

    题目:https://vjudge.net/contest/242286#problem/A Goldbach's conjecture is one of the oldest unsolved p ...

  7. poj 2262 Goldbach's Conjecture(筛素数)

    2018-5-23 验证哥德巴赫猜想,直接将素数全部筛出来,然后从小到大枚举即可,找到的第一个满足条件的肯定就是差值最大的即满足题意的. 普通筛素数: #include<iostream> ...

  8. NUC1090 Goldbach's Conjecture【哥德巴赫猜想 】

    Goldbach's Conjecture 时间限制: 1000ms 内存限制: 65536KB 问题描述 In 1742, Christian Goldbach, a German amateur ...

  9. 哥德巴赫猜想c语言 思路,01-哥德巴赫猜想(Goldbach's Conjecture)--(C语言)

    goldbach-partitions-of-the-even.png 前言 哥德巴赫猜想是(Goldbach's Conjecture)是数论中存在最久的未解问题之一,是一个伟大的世界性的数学猜想, ...

最新文章

  1. AI复活「她」!用GPT-3复刻逝去未婚妻,美国小哥让挚爱以数字形态永生
  2. Office365 用户同步排错思路
  3. python图形编程基础-Python从基础到入门系列教程
  4. libvirt虚拟机管理常用指令
  5. wap手机网页html5通过特殊链接移动设备:打电话,发短信,发邮件详细教程
  6. VS2008环境下开发的某些程序在其他机器运行提示“由于应用程序配置不正确,应用程序未能启动”的问题(IIS)...
  7. python判断成语是abac型_ABAC型的成语
  8. access简述报表的功能_报表的主要功能_access标签报表有什么作用
  9. 「BZOJ1597」[Usaco2008 Mar] [TYWZOJ1482] 土地购买
  10. c语言srand函数作用,C语言之rand()和srand()函数
  11. 2020年webpack面试题
  12. 安卓读取U盘容量信息,支持低版本API
  13. Allegro PCB 软件自动检查走线是否跨分割
  14. Sigar 获取CPU和Memory内存等信息使用详解
  15. 【课内学习】数字电路Flip-Flop
  16. UDT的连接建立和释放
  17. 谷胱甘肽(GSH)修饰的CdTe/CdS量子点(GSH-CdTe/CdSQDs)|PEG修饰水溶性量子点ZnS:Mn
  18. replace()方法
  19. 禁止穿透 uniapp
  20. 《清醒思考的艺术》读书笔记

热门文章

  1. C++的文艺复兴: Why C++? 王者归来
  2. 明天一定要记得放一个硬币在口袋
  3. 工作流的设计,业务流程图的绘制与编辑,工作流软件,工作流源代码组件库,开发平台,开发引擎...
  4. CSS样式表的规划与组织
  5. PyOpenCV 基本操作
  6. 【20171025中】alert(1) to win 脚本渲染自建
  7. android第三方登录appid,AndroidQQ第三方登录
  8. java的string访问某个元素_C#深究.net常用的23种设计模式之访问者模式(Vistor Pattern)...
  9. java二叉树删除子树_132-BST删除有一颗子树的结点
  10. JavaScript常用工具类整理(总结版)