一本通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]范围内的偶数,要你将它表示 ...
随机推荐
- 静态工厂方法和实例工厂方法及普通的bean
容纳你的bean bean工厂:最简单的容器,提供了基础的依赖注入支持.创建各种类型的Bean. 应用上下文(ApplicationContext):建立在bean工厂基础之上,提供系统架构服务. ...
- Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml
解决方法来源:http://www.cnblogs.com/kaka-bing/archive/2012/10/31/2747490.html 问题描述: 使用Android SDK Manager检 ...
- [c.c.a.m.AgentManagerImpl] (AgentConnectTaskPool-39:ctx-c37090c5) Failed to handle host connection: java.lang.IllegalArgumentException: Can't add host: with h
如果无法添加成功,/etc/redhat-release文件覆盖过去 cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core)Red H ...
- day76
昨日回顾: 1 ajax 什么是ajax:异步的JavaScript 和xml 2 特点:异步,局部刷新 3 简单的与后台交互:(携带数据:可以拼到url上---->从GET中取,) ...
- Android导入AS工程
AS 导入工程 还得 新建工程贴代码
- Spark(Python) 从内存中建立 RDD 的例子
Spark(Python) 从内存中建立 RDD 的例子: myData = ["Alice","Carlos","Frank"," ...
- 利用Github搭建自己的博客
教程链接:搭建个人博客 嘿嘿嘿!!一直想自己搭建博客的,一直没机会,这次终于把博客搭了起来.虽然只是一个壳子..套了别人的模板~不过还是很令人兴奋哟!总的来说,就按照这个教程一直往下走,其中有一个坑就 ...
- [arc102E]Stop. Otherwise...[容斥+二项式定理]
题意 给你 \(n\) 个完全相同骰子,每个骰子有 \(k\) 个面,分别标有 \(1\) 到 \(k\) 的所有整数.对于\([2,2k]\) 中的每一个数 \(x\) 求出有多少种方案满足任意两个 ...
- Sterling B2B Integrator与SAP交互 - 01 简介
公司近期实施上线了SAP系统,由于在和客户的数据交互中采用了较多的EDI数据交换,且多数客户所采用的EDI数据并不太相同(CSV,XML,X12,WebService),所以在EDI架构上选择了IBM ...
- Vxlan抓包
实验目的:验证Openstack vxlan组网模式验证虚拟机数据是否通过物理网卡流出 一. 同网段不同主机间虚拟机通讯 (同网段通讯直接通过物理机隧道口链接对端物理机隧道口,不需要通过网络节点): ...