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 ...
随机推荐
- JSP笔记03——环境搭建(转)
不完全翻译,结合谷歌,一定主观性,还可能有误,原始内容地址:https://www.tutorialspoint.com/jsp/jsp_environment_setup.htm [注释]这篇貌似有 ...
- 【Head First Servlets and JSP】笔记8:监听者
1.你不用了解所有监听者API,并不多,一共有8个.不过,你需要知道你能监听什么,以便在需要的时候可以查. 2.关于Session和Cookie.参见JavaWeb学习总结(十二)——Session ...
- JMeter学习(十三)JMeter使用中遇到的问题:Jmeter Debug - "Unrecognized VM option '+HeapDumpOnOutOfMemoryError"
启动JMeter.bat的程序时,出现以下出错信息: Unrecognized VM option '+HeapDumpOnOutOfMemoryError' Could not create the ...
- maven 简介 —— maven权威指南学习笔记(一)
maven是什么?有什么用? Maven是一个项目管理工具,它包含了 一个项目对象模型 (Project Object Model), 一组标准集合, 一个项目生命周期(ProjectLifecycl ...
- RabbitMQ自动补偿机制(消费者)及幂等问题
如果消费者 运行时候 报错了 package com.toov5.msg.SMS; import org.springframework.amqp.rabbit.annotation.RabbitHa ...
- Oracle数据库连接生成DataX的job-Json
package com.bbkj.main; import com.bbkj.DbUtils.ConnectionPoolManager; import com.bbkj.DbUtils.DbUtil ...
- 移动端的坑 之 在可编辑的div中实现placeholder
1.当我们个 div 设置了 contenteditable = "true" 这个块状元素就可以编辑了, 如果要实现 placeholder 直接写上去是没有效果的 <d ...
- 对象存储API
使用对象存储API步骤: 1.购买腾讯云对象存储(COS)服务 2.在腾讯云 对象存储控制台 里创建一个Bucket 3.在控制器 个人API密钥 页里获取APPID,SecretID,SecretK ...
- DEDE整站动态化或整站静态化设置方法
简单说下的是,网站空间小而数据库还可以的话,使用动态浏览也是不错的,但是官方的程序默认的生成静态浏览的,只要一发布文章,就会自动生成静态页面,难道做发布文章还要一个一个去更改其他的设置吗?麻烦.对于采 ...
- 解决:AttributeError: module 'requests' has no attribute 'get'”
今天学习Requests库,当用pip install requests安装后,写了一段代码报错:AttributeError: module 'requests' has no attribute ...