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筛法)的更多相关文章

  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 数学常识 难度:0

    题目链接:http://poj.org/problem?id=2262 哥德巴赫猜想肯定是正确的 思路: 筛出n范围内的所有奇质数,对每组数据试过一遍即可, 为满足b-a取最大,a取最小 时空复杂度分 ...

  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 2262 筛法求素数(巧妙利用数组下标!)

    Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41582   Accepted: ...

  9. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

随机推荐

  1. node中的对象

    1. class的概念 定义一个class,属性都是private,方法都是public. Hello.js: 使用class index.js: 2. 单例类 使用exports而不是module. ...

  2. ios获取设备手持方向——电子罗盘

    转:http://book.51cto.com/art/201411/457105.htm 2014-11-15 19:07 张亚飞/崔巍 中国铁道出版社 字号:T | T 综合评级: 想读()  在 ...

  3. 不同linux下两网卡绑定方法

    记得原来在做性能测试时,为了提高网络吞吐率.必须将两个网卡绑定一起工作.绑定方法如下: 一.CentOS 配置   1.编辑虚拟网络接口配置文件,指定网卡IP: # vi /etc/sysconfig ...

  4. 如何判断SharedPreferences 记录存在

    private EditText et; private String ettext; SharedPreferences settings; Editor editor; //设置 settings ...

  5. DG快照备库

    1.使用快照先决条件:主备库开启闪回功能 2.把备库转为快照库 DGMGRL> convert database satest to SNAPSHOT STANDBY; Converting d ...

  6. 微信小程序 --- 拨打电话

    拨打电话:wx.makePhoneCall btnclick:function(){ wx.makePhoneCall({ phoneNumber:'12580' }); }

  7. Andrew Ng机器学习公开课笔记 -- 朴素贝叶斯算法

    网易公开课,第5,6课 notes,http://cs229.stanford.edu/notes/cs229-notes2.pdf 前面讨论了高斯判别分析,是一种生成学习算法,其中x是连续值 这里要 ...

  8. form表单上传图片问题:线下可以而线上不可以

    由于上传图片需要一定时间,而线下速度快线上速度慢. 所以如果你的上传窗口是弹出界面,那么就会面临上传未完成就关闭了该界面.导致上传失败.

  9. python初识(三)

    目录: 字符编码 文件操作 循环结构拾遗 函数 整体介绍 函数的参数 函数的返回值 函数的调用 自定义函数 一.字符编码 1.了解字符编码的知识储备 a. 文件编辑存取文件的原理(nodepad++, ...

  10. Ambari Rest api 使用

    最近由于项目的需要在看一些Ambari的api去获取集群的一些信息,获取集群节点的状态信息以及各个服务和组件的信息.然后在我们的数据服务管理平台上去做一些监控运维,现在把一些使用总结一下:官网rest ...