poj 2262 Goldbach's Conjecture——筛质数(水!)
题目:http://poj.org/problem?id=2262
大水题的筛质数。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e6;
int n,pri[N+],cnt;
bool vis[N+];
void init()
{
for(int i=;i<=N;i++)
{
if(!vis[i])pri[++cnt]=i;
for(int j=;j<=cnt&&(long long)i*pri[j]<=N;j++)
{
vis[i*pri[j]]=;
if(i%pri[j]==)break;
}
}
}
int main()
{
init();
while()
{
scanf("%d",&n);if(!n)return ;
bool flag=;
for(int i=;i<=cnt&&n>pri[i];i++)
if(!vis[n-pri[i]])
{
printf("%d = %d + %d\n",n,pri[i],n-pri[i]);
flag=;break;
}
if(!flag)printf("Goldbach's conjecture is wrong.\n");
}
}
poj 2262 Goldbach's Conjecture——筛质数(水!)的更多相关文章
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- POJ 2262 Goldbach's Conjecture 数学常识 难度:0
题目链接:http://poj.org/problem?id=2262 哥德巴赫猜想肯定是正确的 思路: 筛出n范围内的所有奇质数,对每组数据试过一遍即可, 为满足b-a取最大,a取最小 时空复杂度分 ...
- POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
http://poj.org/problem?id=2262 题意: 哥德巴赫猜想,把一个数用两个奇素数表示出来. 思路:先用Eratosthenes筛法打个素数表,之后枚举即可. #include& ...
- poj 2262 Goldbach's Conjecture
素数判定...很简单= =.....只是因为训练题有,所以顺便更~ #include<cstdio> #include<memory.h> #define maxn 50000 ...
- POJ 2262 Goldbach's Conjecture(素数相关)
POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- Goldbach's Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想
题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i] i这个数是不是素数 在线性筛后面加个装桶循环即可 #inc ...
- poj2262 Goldbach's Conjecture——筛素数
题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...
随机推荐
- cookie的路径和域
1.Cookie的路径介绍 我们知道Cookie 的属性有很多,其中有一个属性是路径path.有些人认为Cookie 的路径指的是Cookie 在客户端的保存路径,其实并不是.Cookie 的路径是相 ...
- WEB-INF有关的目录路径总结、转向方式: forward 重定向方式: Redirect
WEB-INF有关的目录路径总结 1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提 ...
- Windows下MarialDB使用
命令行控制启动和关闭:mysqld --console #这样启动ctrl+c即为关闭 启动:双击mysqld.exe即可 #此为后台启动 关闭:mysqladmin -uroot -pr ...
- nodejs实现静态托管
const express = require("express"); const app = express(); /* 语法1: app.use(express.static( ...
- Go struct tag
struct成员变量标签(Tag)说明 要比较详细的了解这个,要先了解一下golang的基础,在golang中,命名都是推荐都是用驼峰方式,并且在首字母大小写有特殊的语法含义:包外无法引用.但是由经常 ...
- python中threading多线程
python中有两个处理多线程的模块thread和threading.其中thread提供了多线程底层支持的模块,以低级原始的发那个是来处理和控制线程,使用起来较为复杂:而threading基于thr ...
- Lucene简单介绍
[2016.6.11]以前写的笔记,拿出来放到博客里面~ 相关软件: Solr, IK Analyzer, Luke, Nutch;Tomcat; 1.是什么: Lucene是apache软件基金会j ...
- BZOJ-1396: 识别子串
后缀自动机+线段树 先建出\(sam\),统计一遍每个点的\(right\)集合大小\(siz\),对于\(siz=1\)的点\(x\),他所代表的子串只会出现一次,设\(y=fa[x]\),则这个点 ...
- pylab.show()没有显示图形图像(python的matplotlib画图包)
no display name and no $DISPLAY environment variable ============================ @Neil's answer is ...
- 【P2325】王室联邦(树的遍历+贪心)
在肖明 #神#的推荐下,我尝试了这个题,一开始想的是暴力枚举所有的点,然后bfs层数,试着和肖明 #神#说了这种方法之后, #神#轻蔑的一笑,说这不就是一个贪心么,你只需要先建树,然后从底下向上遍历, ...