POJ 2262 Goldbach's Conjecture 数学常识 难度:0
题目链接:http://poj.org/problem?id=2262
哥德巴赫猜想肯定是正确的
思路:
筛出n范围内的所有奇质数,对每组数据试过一遍即可,
为满足b-a取最大,a取最小
时空复杂度分析:
在1e6内约有8e4个奇质数,因为a <= b,时间复杂度在T*4e4+1e6等级.一般T为1e3,足以承受
空间复杂度为1e6,足以承受
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + ;
int n;
bool ntp[maxn];
int prime[maxn],cnt;
void judgeprime()
{
for(int i = ;i < maxn;i += )
{
if(ntp[i])continue;
prime[cnt++] = i;
for(int j = ;j * i < maxn;j += )
{
ntp[i * j] = true;
}
} } int main()
{
judgeprime();
while(scanf("%d",&n)== && n)
{
for(int i = ;i < cnt && i < n / ;i++)
{
if(!ntp[n - prime[i]])
{
printf("%d = %d + %d\n",cnt,prime[i],n - prime[i]);
break;
}
}
}
return ;
}
POJ 2262 Goldbach's Conjecture 数学常识 难度:0的更多相关文章
- 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(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 ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- POJ 1062 昂贵的聘礼 最短路 难度:0
http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...
随机推荐
- poj2986A Triangle and a Circle&&poj3675Telescope(三角形剖分)
链接 2986是3675的简化版,只有一个三角形. 这题主要在于求剖分后三角形与圆的相交面积,需要分情况讨论. 具体可以看此博客 http://hi.baidu.com/billdu/item/703 ...
- 杨辉三角 && 鸽兔同校
杨辉三角: 用个一维数组直接模拟就行,只是 C++ 的高精度调了好久,后来发现能用 python ,于是试着写了写: dp = [] def out(L, end): for i in range(e ...
- 【CDN】海外免费加速CDN:Incapsula,CloudFare
最近服务器要搬迁到香港,因为后续有国外用户使用,基于此要使用大陆和海外都比较好的cdn才好 一开始国外同事推荐CloudFare,后来看看效果开始使用Incapsula CloudFare 官网:ht ...
- 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...
- CentOS查看内核版本,位数,版本号 (zhuan)
http://blog.csdn.net/painsonline/article/details/7668824 ******************************************* ...
- 20160815_Redis安装
OS: CentOS6.4(x64) 参考网址: http://www.cnblogs.com/haoxinyue/p/3620648.html http://www.codeceo.com/arti ...
- Java跟Javac,package与import
今天讨论一下2个指令与2个关键字. 这次的没有IDE环境,直接在txt文本里编程,在cmd里编译运行,搞清楚java的文件结构,还有怎么设置编译器查找类的路径.首先是javac,有一个可带参数java ...
- python2 urllib 笔记
python2 urllib 笔记 import urllib base='http://httpbin.org/' ip=base+'ip' r=urllib.urlopen(ip) print r ...
- 日期操作类--GregorianCalendar类
GregorianCalendar--API JavaTM Platform Standard Ed. 6 GregorianCalendar类 Calendar类实现了公历日历,GregorianC ...
- robotframework笔记22
创建测试库 支持的编程语言 机器人框架本身是用写的 Python 和自然的测试 库扩展它可以使用相同的实现 语言. 运行时框架上 Jython ,图书馆也可以 实现使用 Java . 纯Python代 ...