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. nodejs 环境搭建

    一 下载nodejs 官网:http://nodejs.cn/ 有时官网有点慢,可以去其他地方下载 统一下载站:http://www.3987.com/xiazai/2/43/57188.html 二 ...

  2. 百度地图api定位和导航简写

    function locate() { // 百度地图API功能 var map = new BMap.Map("allmap"); // 创建Map实例 var point = ...

  3. 170509、文本编辑器编写的shell脚本在linux下无法执行的解决方法

    今天碰到一个奇怪的问题,编写好的shell脚本再linux上执行一直提示找不到文件或目录,后来想想是文本编辑器的问题,记录下来!!! 1.查看当前文本格式 Notepad++界面中,在右下角有文件格式 ...

  4. ebay商品基本属性组合成数据表格式,可用上传到系统递交数据

    该刊登表设计是利用VB写的,当时因为两个系统的数据不能直接对接,又copy并且组合SKU,一个表格一个表格填写,比较麻烦,还好刊登系统可以允许用excel表格上传数据 所以就下好模板,学了VB语言,在 ...

  5. Android N 通知概览及example

    概述 Android App的通知在维护你的App和用户之间的交互起着举足轻重的作用,为了提供更好的用户体验,Android N上的通知提供了可视化刷新,自定义视图和直接回复等功能.另外还提出了Mes ...

  6. mysql添加federated引擎实现dblink远程表访问

    查看mysql数据库federated引擎是否开启. show engines; 若没有开启federated则在mysql配置文件my.cnf中mysqld中添加federated. 在远程数据库中 ...

  7. collision weaknesses

    15.1. hashlib — Secure hashes and message digests — Python 3.5.6 documentation https://docs.python.o ...

  8. htop 分析 进程对资源的消耗

    [root@d ~]# htop -hhtop 2.2.0 - (C) 2004-2018 Hisham MuhammadReleased under the GNU GPL. -C --no-col ...

  9. ubuntu video,gdm swith

    如果已经安装LightDM和GDM登录显示器.那么在Ubuntu下怎么在各种DM间任意切换呢? 以切换到GDM为例,打开终端,使用命令: sudo dpkg-reconfigure gdm 如果已经安 ...

  10. Nginx高级玩法

    1. Nginx获取自定义消息头 .nginx是支持读取非nginx标准的用户自定义header的,但是需要在http或者server下开启header的下划线支持: underscores_in_h ...