一本通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]范围内的偶数,要你将它表示 ...
随机推荐
- Python2.7-difflib
difflib主要用于比较两个序列的不同,常见于字符串的比较,可以对差异生成报告.SequenceMatcher 主要用于找两者相似部分,以及两者不同的转换方法,而 Differ 更注重于比较两者的区 ...
- 没事做的Delphi版的俄罗斯方块游戏Demo
源代码下载
- 6、使用jconsole+VisualVM分析JVM
一.不断增加对象触发GC的代码 VM 参数:-Xms100m -Xmx100m -XX:+UseSerialGC import java.util.ArrayList; import java.uti ...
- mfc 进程的优先级
知识点: 进程优先级 获取当前进程句柄 优先级设置 优先级变动 优先级获取 一.进程优先级(优先级等级) 简单的说就是进程(线程)的优先级越高,那么就可以分占相对多的CPU时间片. ...
- MFC Timer定时器
知识点: 定时器Timer 创建定时器 销毁定时器 代码测试 一. 创建定时器 UINT SetTimer( HWND hWnd, // 指定关联定时器的窗口句柄,在MFC版将省略此参数 UINT n ...
- ubuntu 12.04 桌面版关闭图形界面
对于12.04的ubuntu桌面系统,如果想在开机的时候直接进入字符界面,那可以: 编辑文件 /etc/init/lightdm.conf,在第12行附近,原句“ and runlevel [!06] ...
- python 回溯法 子集树模板 系列 —— 18、马踏棋盘
问题 将马放到国际象棋的8*8棋盘board上的某个方格中,马按走棋规则进行移动,走遍棋盘上的64个方格,要求每个方格进入且只进入一次,找出一种可行的方案. 分析 说明:这个图是5*5的棋盘. 图片来 ...
- 对JSON传递图片Base64编码的一点总结
项目中跟Java对接的时候需要传输图片,经过Base64编码后传输的. 但是实际调试的时候发现Java那边始终无法正常解析出图片. 冷静想想之后,发现问题在于使用OpenCV读取图片,编码的是Mat: ...
- MIT一牛人对数学在机器学习中的作用给的评述
MIT一牛人对数学在机器学习中的作用给的评述 转载自http://my.oschina.net/feedao/blog/52252,不过这个链接也是转载的,出处已经无从考证了. 感觉数学似乎总是不 ...
- 2_C语言中的数据类型 (九)数组
1 数组 1.1 一维数组定义与使用 int array[10];//定义一个一维数组,名字叫array,一共有10个元素,每个元素都是int类型的 array[0] = ...