题目链接: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的更多相关文章

  1. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. poj 2262 Goldbach's Conjecture——筛质数(水!)

    题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...

  3. POJ 2262 Goldbach's Conjecture (打表)

    题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...

  4. POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)

    http://poj.org/problem?id=2262 题意: 哥德巴赫猜想,把一个数用两个奇素数表示出来. 思路:先用Eratosthenes筛法打个素数表,之后枚举即可. #include& ...

  5. poj 2262 Goldbach's Conjecture

    素数判定...很简单= =.....只是因为训练题有,所以顺便更~ #include<cstdio> #include<memory.h> #define maxn 50000 ...

  6. POJ 2262 Goldbach&#39;s Conjecture(素数相关)

    POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...

  7. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  8. 快速切题 poj 1003 hangover 数学观察 难度:0

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103896   Accepted: 50542 Descr ...

  9. POJ 1062 昂贵的聘礼 最短路 难度:0

    http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...

随机推荐

  1. Linux crontab 定时任务

    http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html 19. crontab 定时任务 通过crontab 命令,我们 ...

  2. iOS开发之真机测试

    profile 位置在  /Users/userName/Library/MobileDevice/Provisioning Profiles /Users/user_lzz/Library/Mobi ...

  3. jprofiler安装图解及破解码

    原文:http://blog.csdn.net/lifuxiangcaohui/article/details/38677889 环境: 1.sun jdk1.6.0 2.jprofiler_wind ...

  4. 转载---jboss简单使用

    初学Jboss,对于Jboss的基础认识以及配置做一些记录 Jboss基础: JBoss是什么–基于J2EE的应用服务器–开放源代码–JBoss核心服务不包括支持servlet/JSP的WEB容器,一 ...

  5. iOS开发 字符串MD5加密

    /*** MD5 ***/ #define CC_MD5_DIGEST_LENGTH    16          /* digest length in bytes */ #define CC_MD ...

  6. mixamo fuse三维角色制作

    软件下载: http://www.cgtsj.com/cg/yj/1302/index.html 资源名称: Mixamo Fuse三维角色制作软件V1.3版 本站编号:  YJ1302 百度网盘:下 ...

  7. 【转】 简单理解Socket

    题外话 前几天和朋友聊天,朋友问我怎么最近不写博客了,一个是因为最近在忙着公司使用的一些控件的开发,浏览器兼容性搞死人:但主要是因为这段时间一直在看html5的东西,看到web socket时觉得很有 ...

  8. apt-get remove, apt-get autoremove和aptitude remove的区别

    这篇文章的图片链接发生了问题,无法正常查看图片,所以我在CSDN转载一下,特此声明. apt-getremove的行为我们很好理解,就是删除某个包的同时,删除依赖于它的包,例如:A依赖于B, B依赖于 ...

  9. 【Problem solved】 error C2665: “loadimage”: 2 个重载中没有一个可以转换所有参数类型

    选择“项目”菜单->项目属性->配置属性->常规->字符集,改为“未设置”即可.

  10. Python 练习 11

    #!/usr/bin/python # -*- coding: UTF-8 -*- import math for i in range(10000): #转化为整型值 x = int(math.sq ...