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. [转帖]双剑合璧:CPU+GPU异构计算完全解析

    引用自:http://tech.sina.com.cn/mobile/n/2011-06-20/18371792199.shtml 这篇文章写的深入浅出,把异构计算的思想和行业趋势描述的非常清楚,难得 ...

  2. 根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换

    转:http://blog.csdn.net/q445697127/article/details/40537945 /** * 根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换 ...

  3. ios 给键盘上面加上“完成”

    #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController<UITextFieldDelega ...

  4. Unity3D笔记三 物理引擎

    一.物理引擎 1.物理引擎就是模拟真实世界中物体碰撞.跌落等反应,通过Ballance.愤怒的小鸟来理解什么是物理引擎.Unity的物理引擎使用的是NviDIA的PhysX.2.选中一个游戏对象,主菜 ...

  5. 我的天$删除注册表$安装mysql最后一步不能启动服务的解决办法

    我是照着参考资料一步一步删除的,只是我的Win7 64位的电脑比较犟,硬是要我重启电脑才能成功!强烈建议最好是重启电脑再装! 使用MySQL都有过重装的经历,要是重装MySQL基本都是在最后一步通不过 ...

  6. 从零搭建 vue-cli 脚手架

    前言: 用了几次 vue-cli 做 vue 项目,感觉没什么大问题,虽然也没有用 vue-router 和 vuex .但是心里一直有个梗,就是最初的目录生成和配置文件,一直没动过,也不知道具体原理 ...

  7. 爬虫之selenium使用

    详细使用链接: 点击链接 selenium介绍: selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质 ...

  8. qt——exec()的基本用法

    qt中 if(my1.exec()==QDialog::Accepted) 是什么意思 这个先说这个my1.exec()这个就是个等待消息的循环,就是说它在等待你给的命令. 再说这个QDialog:: ...

  9. python 类 __call__

    __call__ 对象后面加括号,触发执行. 即:对象() 或者 类()() class dog(object): def __init__(self,name): self.name = name ...

  10. ViewPager添加小圆点

    ViewPager添加小圆点很简单,但是如果是网络图片可能就不太好做了,所以我这里给出一种方法,当然你也可以用其他的 1.主界面xml <?xml version="1.0" ...