
poj 2262【素数表的应用---判断素数】【哈希】
View Code
发布日期:2021-05-09 04:14:01
浏览次数:17
分类:博客文章
本文共 1912 字,大约阅读时间需要 6 分钟。
Goldbach's Conjecture
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 35214 | Accepted: 13493 |
Description
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:
Every even number greater than 4 can be written as the sum of two odd prime numbers.For example:
8 = 3 + 5. Both 3 and 5 are odd prime numbers. 20 = 3 + 17 = 7 + 13. 42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.) Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.
Input
The input will contain one or more test cases. Each test case consists of one even integer n with 6 <= n < 1000000. Input will be terminated by a value of 0 for n.
Output
For each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong."
Sample Input
820420
Sample Output
8 = 3 + 520 = 3 + 1742 = 5 + 37 题目大意:给出一个6-1000000的偶整数n,判断是不是两个素数的和,如果是,按照要求的格式输出这两个素数,如果不是或者是n是奇数,输出“Goldbach's conjecture is wrong.”;输入0时退出程序。 这道题需要用到素数表,不过不用打印,只需要标记下谁是素数即可,所以只需要将打印素数表的代码稍微一修改就可以了。
1 #include2 #include 3 using namespace std; 4 int prime[1001000]={0}; 5 int top=0; 6 void print_prime() 7 { 8 int i; 9 double x=sqrt(1001000.0);10 int n=int(x);11 //cout< < >n;33 if(n==0)break;34 if(n%2==1)35 {36 cout<<"Goldbach's conjecture is wrong."<
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月20日 10时39分26秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
安装rabbitMQ
2021-05-09
javascript 之对象-13
2021-05-09
解决:angularjs radio默认选中失效问题
2021-05-09
java按照关键字指定的key删除redis(支持模糊删除)
2021-05-09
tl-wr742n 怎么设置dns
2021-05-09
Vue基础入门学习
2021-05-09
Spring Validation 校验
2021-05-09
如何使用Postman生成不同格式测试的报告
2021-05-09
Jmeter-ForEach控制器
2021-05-09
Jmeter发送jdbc请求(操作mysql)
2021-05-09
windows环境下安装zookeeper(仅本地使用)
2021-05-09
Docker学习(十三)- docker rm 命令详解
2021-05-09
移动端Web开发调试之Chrome远程调试(Remote Debugging)
2021-05-09
解决Eclipse左键无法查看maven第三方包的源代码,多图亲测可用【转】
2021-05-09
selenium获取Cookie操作
2021-05-09
selnium远程机上传图片遇到的坑
2021-05-09
idea如何编译maven项目
2021-05-09
Kali安装Docker
2021-05-09