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. 蓝桥杯历届试题 危险系数(dfs或者并查集求无向图关于两点的割点个数)

    Description 抗日战争时期,冀中平原的地道战曾发挥重要作用. 地道的多个站点间有通道连接,形成了庞大的网络.但也有隐患,当敌人发现了某个站点后,其它站点间可能因此会失去联系. 我们来定义一个 ...

  2. 对寄存器ESP和EBP的一些理解

    PS:EBP是当前函数的存取指针.即存储或者读取数时的指针基地址:ESP就是当前函数的栈顶指针. 每一次发生函数的调用(主函数调用子函数)时,在被调用函数初始时,都会把当前函数(主函数)的EBP压栈, ...

  3. 03-Maven坐标管理

    1.什么是坐标? 2.坐标的详细概念 3.Maven包引用

  4. qemu安装

    1 下载qemu wget http://wiki.qemu-project.org/download/qemu-2.4.1.tar.bz2 2 解压qemu tar -jxvf qemu-2.4.1 ...

  5. Linux服务器安全之 fail2ban的安装与配置

    近日在查看Nginx的访问日志中,发现了大量404请求,仔细研究一番发现有人正在试图爆破网站. 我刚上线你就企图攻击我?????? 这怎么能忍.. 于是乎 --- 查资料后得知有一个神奇的工具 fai ...

  6. 20155210 EXP6 信息搜集与漏洞扫描

    20155210 EXP6 信息搜集与漏洞扫描 信息搜集 外围信息搜集 通过DNS和IP挖掘目标网站的信息 whois 域名注册信息查询 我们通过输入whois qq.com可查询到3R注册信息,包括 ...

  7. CF708D Incorrect Flow

    CF708D Incorrect Flow 有源汇上下界最小费用可行流.(= =) 对每条给定的边连边: 首先\(f_i\)是给定的,所以要有一条这个边而且要流满,先\(a_i-b_i\)连一条上下界 ...

  8. 【Android UI设计与开发】第02期:引导界面(二)使用ViewPager实现欢迎引导页面

    本系列文章都会以一个程序的实例开发为主线来进行讲解,以求达到一个循序渐进的学习效果,这样更能加深大家对于程序为什么要这样写的用意,理论加上实际的应用才能达到事半功倍的效果,不是吗? 最下方有源码的下载 ...

  9. 【Direct2D1.1初探】Direct2D特效概览

    转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 Direct2D是一个基于Direct3D的2D图形API,可以利用硬件加速特性来提供高性能高质量的2D渲染.但 ...

  10. win10+anaconda3+python3.6+opencv3.1.0

    最近用windows系统比较多,就想在win10下搞一下深度学习这一方面的研究,那么就需要配置好环境巴拉巴拉的一堆东西.默默记个笔记,正所谓“好记性不如烂笔头”. 1.安装Anaconda 这个是一个 ...