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的更多相关文章

  1. Goldbach’s Conjecture(信息学奥赛一本通 1622)

    [题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=1 ...

  2. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  3. Twin Prime Conjecture(浙大计算机研究生保研复试上机考试-2011年)

    Twin Prime Conjecture                                            Time Limit: 2000/1000 MS (Java/Othe ...

  4. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  5. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  6. HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...

  7. Goldbach's Conjecture(哥德巴赫猜想)

    Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  8. (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 ...

  9. POJ 2262 Goldbach&#39;s Conjecture(素数相关)

    POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...

随机推荐

  1. Python:基础知识

    python是一种解释型.面向对象的.带有动态语义的高级程序语言. 一.下载安装 官网下载地址:https://www.python.org/downloads 下载后执行安装文件,按照默认安装顺序安 ...

  2. Android解决自定义View获取不到焦点的情况

    引言: 我们在使用Android View或者SurfaceView进行图形绘制,可以绘制各种各样我们喜欢的图形,然后满怀信心的给我们的View加上onTouchEvent.onKeyDown.onK ...

  3. jqgrid 行选中multiboxonly属性说明

    multiboxonly属性值为布尔值. false:点击行时,同时选中改行的复选框,支持多行选中 true:点击行时,只将点击的行处理为选中状态,切换其他行时,原选中行的选中效果被取消 (永远只有一 ...

  4. 简单直白的去理解AOP,了解Spring AOP,使用 @AspectJ - 读书笔记

    AOP = Aspect Oriental Programing  面向切面编程 文章里不讲AOP术语,什么连接点.切点.切面什么的,这玩意太绕,记不住也罢.旨在以简单.直白的方式理解AOP,理解Sp ...

  5. bash 定时任务

    time1=$(date +%s -d '2014-01-13 22:46:05') for((;;)) do time2=$(date +%s) time3=$((time1 - time2)) ] ...

  6. 文件I/O(2)

    文件I/O(2) 文件共享 内核使用三种数据结构表示打开的文件,他们之间的关系决定了在文件共享方面一个进程对还有一个进程可能产生的影响.如图1所看到的. 1)  每一个进程在进程表中都有一个记录项.记 ...

  7. 基于Python自动上传包到nexus仓库

    1.设计思路 用户通过excel表格的形式填写包的信息,并将包一起发送给负责人 2.代码实现 #coding:utf8 import os import xlrd def GetData(fileNa ...

  8. 20155304《网络对抗》Exp4 恶意代码分析

    20155304<网络对抗>Exp4 恶意代码分析 实践内容 1.系统运行监控 1.1使用schtasks指令监控系统运行 我们在C盘根目录下建立一个netstatlog.bat的文本文件 ...

  9. Android环境下使用call_usermodehelper()以及调试

    有时候设备驱动需要做一些与其他的设备通信的操作,但是驱动本身又不可以去实作,那这个时候就可以通过调用用户态的软件,通过这个软件和其他的设备进行通信. 那在内核态如何去调用用户态的程序呢?call_us ...

  10. JAVA 文件读取写入后 md5值不变的方法

    假如我们想把某文件读入 StringBuffer 并写入新文件,新文件md5值需要保持不变(写入新文件后保证和源文件一模一样), 我们就需要在操作 StringBuffer 时附加换行符: Strin ...