POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
http://poj.org/problem?id=2262
题意:
哥德巴赫猜想,把一个数用两个奇素数表示出来。
思路:
先用Eratosthenes筛法打个素数表,之后枚举即可。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std; const int maxn = 1e7 + ; int n;
int vis[maxn]; void init()
{
int m = sqrt(maxn + 0.5);
for (int i = ; i < m; i++)
{
if (!vis[i])
for (int j = i*i; j < maxn; j += i)
vis[j] = ;
}
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
init();
while (cin >> n && n)
{
for (int i = ; i < n; i++)
{
if (!vis[i])
{
if (!vis[n - i])
{
printf("%d = %d + %d\n", n, i, n - i);
break;
}
}
}
}
}
POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)的更多相关文章
- 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——筛质数(水!)
题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...
- 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
素数判定...很简单= =.....只是因为训练题有,所以顺便更~ #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 ...
- poj 2262 筛法求素数(巧妙利用数组下标!)
Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41582 Accepted: ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
随机推荐
- ELK基础学习
第壹部分:Elasticsearch 一 .Elasticsearch增删改查1.数据写入:HTTP method:POSTURL:http://127.0.0.1:9200/index-docs-n ...
- Google浏览器提示用户要允许网站允许flash!
开发的flash播放器,在谷歌浏览器上播放不了,需要提示用户手动开启允许网站运行flash: <script type="text/javascript"> if (w ...
- onethink重新安装,提示已安装过解决办法!
onethink完全重新安装的时候提示已安装过,直接跳过数据库安装的解决办法 首先:删除根目录下 Data目录下的 install.lock 文件,然后: 打开\Application\Install ...
- Python 自学积累(一)
1. 当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/pythonS ...
- log4j配置输出到多个日志文件(转)
參考资料:http://logging.apache.org/log4j/1.2/manual.html 通常我们项目里,有一些重要的日志想单独的输出到指定的文件,而不是全总输出到系统的日志文件中.那 ...
- SpringBoot SpringApplication底层源码分析与自动装配
目录 抛出问题 @SpringBootApplication注解剖析 SpringApplication类剖析 第一步:配置SpringBoot Bean来源 第二步 :自动推断SpringBoot的 ...
- 关于cdn原理(就是内容分发网络)
cdn,我理解其本质就是为了解决距离远产生的速度问题,使用就近的服务. 从中国请求美国一台服务器上的图片.一般比较慢,因为距离这么远,网络传输是存在损耗的,距离越远,传输的时间就越长.一般会看到浏览器 ...
- npm基础知识笔记
# NPM Study 1.npm组成 --网站 --命令行界面(CLI) --注册表 2.npm入门-创建属于你的npm账户 --https://www.npmjs.com/signup 5 ...
- UA-* headers
HTTP The Definitive Guide Request headers are headers that make sense only in a request message. The ...
- India and China Origins---hdu5652(二分 + bfs)或者(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5652 题意: 很久以前,中国和印度之间并没有喜马拉雅山相隔,两国的文化交流很频繁.随着喜马拉雅山海拔逐 ...