题目53:Goldbach's Conjecture

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/378803.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Anaconda下安装TensorFlow和OpenCV(都是心血呀~)

从国庆放假到现在的6号&#xff0c;我整整搞了将近五天多。安装个TensorFlow和OpenCV不下五次&#xff0c;各种问题各种解决&#xff0c;下载后卸载&#xff0c;卸载后下载&#xff0c;我快吐了啊这个国庆&#xff0c;但是最终还是达到了自己的目标&#xff08;我太难了&#x…

图像分割-基本边缘检测roberts,prewitt,sobel,canny,laplace

执行边缘检测的三个基本步骤&#xff1a; 1、为降噪对图像进行平滑处理。&#xff08;导数对噪声具有敏感性。图像的正负分量检测困难&#xff09; 2、边缘点的检测。&#xff08;提取边缘点的潜在候选者&#xff09; 3、边缘定位。&#xff08;从候选者中选出真是边缘点成员&a…

goroutine并发扫描MySQL表_goroutine 并发之搜索文件内容

golang并发编程 - 例子解析February 26, 2013最近在看《Programming in Go》, 其中关于并发编程写得很不错, 受益非浅, 其中有一些例子是需要多思考才能想明白的, 所以我打算记录下来, 强化一下思路《Programming in Go》在 Chapter 7. Concurrent Programming 里面一共用3个例…

软件开发模型和软件过程模型_什么是软件和软件过程?

软件开发模型和软件过程模型软件 (Software) Software is a set of instructions which instructs the computer for performing different operations. Software is nothing else but a general name for computer programs. 软件是一组指令&#xff0c;指导计算机执行不同的操…

甲骨文CEO埃里森称将在Sun裁员1000人

据国外网站报道&#xff0c;甲骨文CEO拉利埃里森周三表示&#xff0c;在完成对Sun的收购后&#xff0c;将对该公司裁员1000人。不过他同时也表示&#xff0c;未来几个月还要新雇2000人加强Sun的业务。 分析师们曾预测甲骨文完成收购后&#xff0c;将在Sun大裁员。不过埃里森和甲…

改变Jupyter的默认项目路径

开始接触Jupyter&#xff0c;看见它默认的工作路径是C盘&#xff0c;很难受想换下工作空间路径 管理员身份打开你的Anaconda Prompt 输入jupyter notebook --generate-config&#xff0c;找到你的配置文件位置 修改一下路径即可 一般情况到这一步就已经修改成功了&#xff…

arm-linux-gcc/ld/objcopy/objdump使用总结[zz]

地址&#xff1a;http://hi.baidu.com/xiaoyue1800/item/a11a2c4a26da4b04c11613d9arm-linux工具的功能如下&#xff1a;arm-linux-addr2line 把程序地址转换为文件名和行号。在命令行中给它一个地址和一个可执行文件名&#xff0c;它就会使用这个可执行文件的调试信息指出在给…

图像分割-LOG检测器和DOG检测器

边缘检测是以较小的算子为基础的&#xff0c;具有两个建议 1、灰度变化与图像尺寸无关&#xff0c;因此检测要求使用不同尺寸的算子。 2、灰度的突然变化会在一阶导数产生波峰波谷&#xff0c;在二阶导数产生零交叉 大的算子检测模糊边缘&#xff0c;小的算子检测锐度集中的细节…

java const string_深入研究Java String

开始写 Java 一年来&#xff0c;一直都是遇到什么问题再去解决&#xff0c;还没有主动的深入的去学习过 Java 语言的特性和深入阅读 JDK 的源码。既然决定今后靠 Java吃饭&#xff0c;还是得花些心思在上面&#xff0c;放弃一些打游戏的时间&#xff0c;系统深入的去学习。Java…

python 示例_带有示例的Python字典update()方法

python 示例字典update()方法 (Dictionary update() Method) update() method is used to update the dictionary by inserting new items to the dictionary. update()方法用于通过将新项目插入字典来更新字典。 Syntax: 句法&#xff1a; dictionary_name.setdefault(itera…

Rsync 使用指南

Rsync是个相当棒的同步工具&#xff0c;比如&#xff1a;1. 如何做本地两个目录之间的同步&#xff1f;rsync -av --delete --force ~/Desktop/Miscs/ /media/disk/DesktopMiscs 这样就可以做~/Desktop/Miscs目录的镜像了。/media/disk是我的移动硬盘的挂载点。这里关键有个问题…

C++——统计多行单个字符类型个数

键盘输入n个字符&#xff0c;请分别统计大写字母、小写字母、数字、其他字符的个数并输出&#xff1b;还需要输出所有数字字符之和 【输入形式】 第一行为一个整数n(100 > n > 0)&#xff0c;接下来n行每行一个字符 【输出形式】 输出第1行为4个整数&#xff0c;分别…

安卓项目4

经历两天的琢磨&#xff0c;终于把android连接服务器端php&#xff0c;读取mysql这一块弄好了。 先说说这几天遇到的问题。 http://wenku.baidu.com/view/87ca3bfa700abb68a982fbca.html 这是我参照的资料&#xff0c;原先我一度认为是不能实例化ServiceLink类&#xff0c;后来…

system getenv_Java System类getenv()方法及示例

system getenv系统类getenv()方法 (System class getenv() method) getenv() method is available in java.lang package. getenv()方法在java.lang包中可用。 getenv() method is used to return an unmodifiable Map of the current environment variable in key-value pairs…

用ASP获取客户端IP地址的方法

要想透过代理服务器取得客户端的真实IP地址&#xff0c;就要使用 Request.ServerVariables("HTTP_X_FORWARDED_FOR") 来读取。不过要注意的事&#xff0c;并不是每个代理服务器都能用 Request.ServerVariables("HTTP_X_FORWARDED_FOR") 来读取客户端的真实…

C++——已知a+b、 a+c、b+c、 a+b+c,求a、b、 c

有三个非负整数a、b、 C,现按随机顺序给出它们的两两和以及总和4个整数&#xff0c;即ab、 ac、bc、 abc, 注意,给出的4个数的顺序是随机的&#xff0c;请根据这四个数求出a、b、c是多少? [输入形式] 输入为一-行4个正整数, x1、 x2、x3、 x4 (0≤xi≤10^9) &#xff0c;表示…

DDD:DomainEvent、ApplicationEvent、Command

Command&#xff1a;纵向传递&#xff0c;跨分层&#xff0c;在控制器层和应用层之间传递。 DomainEvent&#xff1a;横向传递&#xff0c;跨聚合&#xff0c;在一个DLL中。 ApplicationEvent&#xff1a;横向传递&#xff0c;跨模块&#xff0c;在不同的DLL中。转载于:https:/…

表示和描述-边界追踪

边界追踪目标&#xff1a; 输入&#xff1a;某一区域的点 输出&#xff1a;这一区域的点的坐标序列&#xff08;顺时针或逆时针&#xff09; Moore边界追踪法&#xff1a; 两个前提条件&#xff1a; 1、图像为二值化后的图像&#xff08;目标为1&#xff0c;背景为0&#xff0…

视频的读取与处理

读取本地视频&#xff0c;以灰度视频输出 import cv2vc cv2.VideoCapture(E:\Jupyter_workspace\study\data/a.mp4)#视频路径根据实际情况而定#检查是否打开正确 if vc.isOpened():open,fream vc.read()#read()返回两个参数&#xff0c;第一个参数为打开成功与否True or Fal…