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 ...
随机推荐
- 【HackerRank】Halloween party
Change language : Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silv ...
- yuv转opencv中的IplImage
http://www.2cto.com/kf/201208/145559.html http://www.opencv.org.cn/forum.php?mod=viewthread&tid= ...
- VCS 常用命令速查
VCS是编译型Verilog模拟器,它完全支持OVI标准的Verilog HDL语言.PLI和SDF.VCS具有目前行业中最高的模拟性能,其出色的内存管理能力足以支持千万门级的ASIC设计,而其模 ...
- 斯坦福机器学习视频笔记 Week4 & Week5 神经网络 Neural Networks
神经网络是一种受大脑工作原理启发的模式. 它在许多应用中广泛使用:当您的手机解释并理解您的语音命令时,很可能是神经网络正在帮助理解您的语音; 当您兑现支票时,自动读取数字的机器也使用神经网络. Non ...
- springboot - web项目
一:使用Thymeleaf:参考http://blog.csdn.net/u012702547/article/details/53784992#t0 1.1 引入相应的包 1.2 thymelea ...
- skynet中的各种锁
最近读skynet c语言部分的源码,发现有好多锁的使用和gcc提供的一些原子操作.看到这些东西,对于我这个newbee来说实在有些hold不住.但为了了解并进一步掌握,还是决定好好分析一下.不足之处 ...
- cern-cloud-architecture
规模: 总体: 有26个Cell 一个数据中心运行控制节点,另外一个仅仅运行nova cell 统一,灵活 nova-api运行在VM中,当然需要至少一个部署在物理机上来启动VM. 每个cell只有一 ...
- ASP.NET上传文件,已经上传的大小保存在session中,在另一个页面中读取session的值不行
想自己做个ASP.NET上传文件时显示进度条的, 按照自己的想法,其实也就是显示每次已经上传的字节,从网上找到一个方法是能够把文件变成流以后再慢慢写入的,我在那个循环写入的时候每循环一次都把已经上传的 ...
- array_merge函数的注意事项
array_merge — 合并一个或多个数组 array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面.返回作为结果的数组 如果输入的数组中有相同的字符串键名 ...
- Linux系统memcached安装
[memcached安装] Linux系统安装memcached可以自动安装,也可以手动编译安装,这里使用手动编译安装 1.Linux系统安装memcached,首先要先安装libevent库. 下载 ...