【POJ - 2909 】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. 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

题目大意:

对于任何大于或等于4的偶数n,存在至少一对素数p1和p2,使得n = p1 + p2。我们认为(p1,p2)和(p2,p1)是相同的。问有多少对。。

解题报告:

  像这种无序的二元组或者无序的三元组啥的,,,为了保证无序,其实只需要满足他是一个递增的就可以了。,就像那道 数的划分  , 一样。写dfs的条件就是是递增的然后去dfs。

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#define MAX 50001//求MAX范围内的素数 
using namespace std;  long long su[MAX],cnt;  
bool isprime[MAX];  
void prime()
{  cnt=1;  memset(isprime,1,sizeof(isprime)); isprime[0]=isprime[1]=0;for(long long i=2;i<=MAX;i++)  {  if(isprime[i]) {su[cnt++]=i; } for(long long j=1;j<cnt&&su[j]*i<MAX;j++)  {  isprime[su[j]*i]=0;}  }  
}  
int main()
{prime();int n;int i,ans = 0; while(scanf("%d",&n) && n ) {ans = 0;for( i= 3; i+i<=n; i+=2) {if(isprime[ i ] == 1 && isprime[n-i] == 1) {ans++;}}printf("%d\n",ans);}return 0 ;} 

 

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

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

相关文章

计算机突然断电恢复供电后,电脑突然断电的坏处有哪些?

对于经常使用计算机进行办公的用户而言&#xff0c;最可怕的事情是计算机在保存文件之前突然断电关机。但是&#xff0c;这对于计算机本身根本不是问题&#xff0c;只要计算机能够正常运行。但是&#xff0c;如果断电导致以下任何一种情况&#xff0c;则需要小心&#xff01;1、…

python函数实例解析_python支持返回函数的实例解析

这篇文章主要介绍了python支持返回函数的实例解析,小编觉得挺不错的&#xff0c;现在分享给大家&#xff0c;也给大家做个参考。一起跟随小编过来看看吧最近接触python,看到了python中返回函数的概念&#xff0c;以前只接触过函数返回值&#xff0c;比如python就可以返回int,st…

【CodeForces - 260D】Black and White Tree (思维构造,猜结论,细节,构造一棵树)

题干&#xff1a; The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesnt contain any cycles. Each node of the graph is painted black or white in such a mann…

手游 自建服务器,英灵神殿自己搭建服务器怎么弄

英灵神殿是一款冒险生存类游戏&#xff0c;在英灵神殿游戏中小伙伴要自己搭建服务器才能玩&#xff0c;那么要怎么搭建&#xff0c;有什么技巧吗?接下来和小编一起来看看吧!Valheim英灵神殿服务器搭建技巧第一步&#xff1a;SteamCMD和安装内容从这里下载SteamCMD。将其提取到…

描写火车站场景_关于描写火车站的句子

关于描写火车站的句子关于描写火车站的句子所以至今&#xff0c;我仍很爱乘火车&#xff0c;卧铺&#xff0c;靠在枕头上看书&#xff0c;沉沉睡去&#xff0c;听铁轨一层一层的荡漾&#xff0c;在记忆中昏暗地穿行&#xff0c;如果我爱谁&#xff0c;我们一定会乘火车去很远的…

【POJ - 1463】Strategic game (树上最小点覆盖,树形dp)

题干&#xff1a; Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree…

vue css自定义标签,Vue如何使用CSS自定义变量

目录在 css 自定义变量的功能以及出来许久了&#xff0c;但实际开发中大家使用并不多。归其原因是因为 less、sass 等预处理器已经拥有定义变量的功能&#xff0c;以及Vue、react很方便设置 style 样式&#xff0c;大家可能觉得使用 css 定义变量不方便且没必要。实则不然举个最…

【CodeForces - 260A】Adding Digits (思维构造)

题干&#xff1a; Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times. One operation of lengthening a number means adding exactly one digit to the number (in the…

人工智能在fpga的具体应用_人工智能带动了FPGA的发展

未来几年&#xff0c;人工智能芯片的需求将急剧上升。联合市场研究公司(Allied Market Research)预估&#xff0c;未来5年&#xff0c;人工智能芯片的需求将以每年近50&#xff05;的速度增长&#xff0c;因为该技术将在汽车、医疗保健等多个领域得到广泛应用。Xilinx深知其中存…

恐怖黎明稳定服务器,恐怖黎明新人联机图文教程 怎么联机-游侠网

恐怖黎明怎么联机?不少玩家想体验联机&#xff0c;但是不知道方法&#xff0c;小编这里给大家带来了新人联机图文教程&#xff0c;不会的萌新来学习下吧。联机图文教程:A1 联机&#xff1a;因为gd(grimdawn)没有自己的战网平台(就是专供联机玩的专职服务器 server)&#xff0c…

【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)

题干&#xff1a; A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". Well say that some date is mentioned in the Prophesy if there is a su…

github 上传代码_leetcode爬虫:爬取代码;生成readme;上传github

Leetcode-Helper哪个程序员 不想一键下写过的代码&#xff0c;自动上传Github&#xff0c;并且还能生成好看的README呢&#xff1f;有用的话点个⭐吧&#xff0c;谢谢你。Leetcode-Helper传送门​github.com主要功能 模拟登陆力扣中国站(leetcode-cn)爬取每题提交的ac代码&…

绝地求生信号枪只能在服务器吗,绝地求生信号枪怎么用?信号枪刷新点及用法详解...

绝地求生信号枪怎么用&#xff1f;信号枪刷新点及用法详解2018-03-15 15:22:12来源&#xff1a;吃鸡小助手编辑&#xff1a;野狐禅评论(0)绝地求生近日更新中悄悄加入了信号枪&#xff0c;引得广大玩家热情满满的在游戏中寻找&#xff0c;信号枪到底怎么用呢&#xff1f;下面就…

spring的beanutils工具类_基于spring-beans实现工具类BeanUtils基于Class实例化注入对象及查找方法、复制属性等操作...

一、前言基于spring-beans(4.1.4)的工具类org.springframework.beans.BeanUtils对注入spring对象按照Class实例化instantiateClass、class对象方法名称methodName查找findMethod、属性查找对于class类信息findPropertyType、对象属性复制copyProperties等常用操作&#xff0c;具…

【CodeForces - 260C】Balls and Boxes (思维模拟,有坑,时光倒流)

题干&#xff1a; Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, lets assume that its number is i, took all balls out from it (it …

文件服务器共享文件夹访问权限,5对文件服务器中的共享文件夹进行访问权限控制...

对文件服务器中的共享文件夹进行访问权限控制1. 实训目的在Windows Server 2003环境下设置文件服务器的目的是要对多用户进行资源共享&#xff0c;这其中经常遇到不同用户应该分配不同权限的问题&#xff0c;通过这个实训希望读者了解Windows Server 2003中访问权限设置方法和具…

java生日正则表达式_java之正则表达式、日期操作

正则表达式和日期操作正则表达式简介正则表达式就是使用一系列预定义的特殊字符来描述一个字符串的格式规则&#xff0c;然后使用该格式规则匹配某个字符串是否符合格式要求。作用:比如注册邮箱,邮箱有用户名和密码,一般会对其限制长度,这个限制长度的事情就是正则表达式做的规…

渲染服务器位置,如何用服务器做渲染

如何用服务器做渲染 内容精选换一换&#xfffd;&#xfffd;&#xfffd;&#xfffd;BoostKit ARMԭ&#xfffd;&#xfffd;ʹ&#xfffd;&#xfffd;&#xfffd;׼&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;嵥&#xfffd;&#xfffd…

【HDU - 2376】Average distance (树,平均距离,算贡献)

题干&#xff1a; Given a tree, calculate the average distance between two vertices in the tree. For example, the average distance between two vertices in the following tree is (d 01 d 02 d 03 d 04 d 12 d 13 d 14 d 23 d 24 d 34)/10 (63799131510122)/10…

读取ppt并存入数据库_Java解析Excel文件并把数据存入数据库

前段时间做一个小项目&#xff0c;为了同时存储多条数据&#xff0c;其中有一个功能是解析Excel并把其中的数据存入对应数据库中。花了两天时间&#xff0c;不过一天多是因为用了"upload"关键字作为URL从而导致总报同一个错&#xff0c;最后在同学的帮助下顺利解决&a…