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. JAVA框架 Spring AOP底层原理

    一:AOP(Aspect Oriented Programming)面向切面编程. 底层实现原理是java的动态代理:1.jdk的动态代理.2.spring的cglib代理. jdk的动态代理需要被代 ...

  2. Fiddler抓包调试前端脚本代码

    0.写在前面的话 之前看了阮一峰老师关于互联网协议入门的博客,受益匪浅,接着再去体会了下HTTP协议,就想着看实际网络访问中的那些HTTP请求头和响应是什么样的.Chrome的调试工具的Network ...

  3. 2017-2018-2 20155224『网络对抗技术』Exp4:恶意代码分析

    原理与实践说明 实践目标 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,systr ...

  4. 4.Xilinx RapidIO核详解

    转自https://www.cnblogs.com/liujinggang/p/10072115.html 一.RapidIO核概述 RapidIO核的设计标准来源于RapidIO Interconn ...

  5. idea 解决 pom.xml 中,maven仓库无法导入的问题(红线)

    只需要用另一篇文章的 maven clean install 功能就行了 idea Cannot Resolve Symbol 问题解决

  6. idea 开启 tomcat 访问日志记录

    all 为 设置为 查看所有类型的请求 (包括ajax)

  7. 移动端H5页面上传图片或多张图片

    传统PC网页上传文件,大家都已经熟悉,这里不做介绍. 本文简单介绍移动端常用上传图片功能.灵活使用轮询或长连接可实现PC与移动端数据同步,即PC端需要上传的图片是移动拍照下来或移动端硬盘储存的,不需要 ...

  8. 【RDB】MariaDB 之事务、复制、集群

    目录 简介 安装启动 权限 事务 脏读.不可重复读.幻读 MVCC 复制 异步复制 半同步复制 GTID复制 集群(Galera) 配置 监控(Zabbix) 简介 环境: CentOS 7.4.17 ...

  9. effective c++ 笔记 (31-34)

    //---------------------------15/04/20---------------------------- //#32   确定你的public继承塑膜出 is-a 关系 { ...

  10. 软件测试为何我会首选Python

    对于软件测试选择什么样的语言去学习,不同的人有不同的回答,为什么我会首选Python呢?这就要从Python的特点与适应领域说了. 一.Python的特点:优雅.明确.简单. 二.Python适合的领 ...