一本通1622Goldbach’s Conjecture
1622:Goldbach’s Conjecture
时间限制: 1000 ms 内存限制: 524288 KB
【题目描述】
原题来自:Ulm Local,题面详见:POJ 2262
哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和。 比如:
8=3+5
20=3+17=7+13
42=5+37=11+31=13+29=19+23
你的任务是:验证小于 106 的数满足哥德巴赫猜想。
【输入】
多组数据,每组数据一个 n。
读入以 0 结束。
【输出】
对于每组数据,输出形如 n=a+b,其中 a,b 是奇素数。若有多组满足条件的 a,b,输出 b−a 最大的一组。
若无解,输出 Goldbach′s conjecture is wrong.。
【输入样例】
8
20
42
0
【输出样例】
8 = 3 + 5
20 = 3 + 17
42 = 5 + 37
【提示】
数据范围与提示:
对于全部数据,6≤n≤106 。
sol:欧拉筛筛出素数后暴力枚举
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
int Prim[N];
bool Bo[N];
inline void Pre_Prime()
{
int i,j;
for(i=;i<=;i++)
{
if(!Bo[i]) Prim[++*Prim]=i;
for(j=;j<=*Prim&&Prim[j]*i<=;j++)
{
Bo[Prim[j]*i]=;
if(i%Prim[j]==) break;
}
}
return;
}
int main()
{
int i;
Pre_Prime();
while(true)
{
bool Flag=;
if(!(n=read())) break;
for(i=;i<=*Prim&&Prim[i]<n;i++) if(!Bo[n-Prim[i]])
{
printf("%d = %d + %d\n",n,Prim[i],n-Prim[i]);
Flag=;
break;
}
if(!Flag)puts("Goldbach's conjecture is wrong.");
}
return ;
}
/*
input
8
20
42
0
output
8 = 3 + 5
20 = 3 + 17
42 = 5 + 37
*/
一本通1622Goldbach’s Conjecture的更多相关文章
- Goldbach’s Conjecture(信息学奥赛一本通 1622)
[题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=1 ...
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Twin Prime Conjecture(浙大计算机研究生保研复试上机考试-2011年)
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Othe ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Goldbach's Conjecture(哥德巴赫猜想)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
- POJ 2262 Goldbach's Conjecture(素数相关)
POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...
随机推荐
- Android 使用第三方登录(QQ和新浪微博)
账号申请什么的我就在这里略过了!(相信大家看看文档都能够处理的)本篇博客仅作引导用--主要提供给哪些不知道怎样入手的朋友.(如果需要更加强大的功能大家可以看一下开放平台上的文档,上面都有的) 使用QQ ...
- Android 关于在ScrollView中加上一个ListView,ListView内容显示不完全(总是显示第一项)的问题的两种简单的解决方案
是这样的哈: 有这样一个需求: 1.显示一个界面,界面上有一个列表(ListView),列表上面有一个可以滚动的海报. 2.要求在ListView滚动的过程中,ListView上面的海报也可以跟着Li ...
- 【转】软件质量之道:SourceMonitor
转:https://blog.csdn.net/feng_ma_niu/article/details/40594799 SourceMonitor是一个源代码衡量工具,由http://www.cam ...
- HDU 3072 Intelligence System(tarjan染色缩点+贪心+最小树形图)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- “System.Reflection.AmbiguousMatchException”类型的异常在 mscorlib.dll 中发生
错误提示: “System.Reflection.AmbiguousMatchException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理. 发现不明确的匹配. 问题原 ...
- VS一些快捷键
参考网址:http://www.open-open.com/lib/view/open1412261028453.html (这里省去了很多大家闭上眼都会操作的什么Ctrl+S 等等操作 给出的大多是 ...
- 2017-2018-2 20155203《网络对抗技术》Exp2 后门原理与实践
基础问题回答 (1)例举你能想到的一个后门进入到你系统中的可能方式? 通过下载带后门的程序或者点开带有后门的软件,或者后门本身就在我的系统里: (2)例举你知道的后门如何启动起来(win及linux) ...
- WPF编程,通过Double Animation动态旋转控件的一种方法。
原文:WPF编程,通过Double Animation动态旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...
- POJ 1988&&2236
并查集,如果只是朴素的路径压缩,那么也就是一句话的事情. 但是,一般都没有这种仁慈的裸题(假的,多了去了) 1988:带权并查集,贼鸡儿像Luogu的那道杨威利的并查集(好像是叫银河英雄传说) 开两个 ...
- Hadoop日记Day15---MapReduce新旧api的比较
我使用hadoop的是hadoop1.1.2,而很多公司也在使用hadoop0.2x版本,因此市面上的hadoop资料版本不一,为了扩充自己的知识面,MapReduce的新旧api进行了比较研究. h ...