poj2262 Goldbach's Conjecture——筛素数
题目:http://poj.org/problem?id=2262
水水更健康~
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int const maxn=1e6;
int n,pri[maxn+],cnt;
bool vis[maxn+];
void init()
{
for(int i=;i<=maxn;i++)
{
if(!vis[i])pri[++cnt]=i;
for(int j=;j<=cnt&&i*pri[j]<=maxn;j++)
{
vis[i*pri[j]]=;
if(i%pri[j]==)break;
}
}
}
int main()
{
init();
while()
{
scanf("%d",&n);
if(!n)return ;
for(int i=;i<=cnt&&pri[i]<=n;i++)
{
if(!vis[n-pri[i]])
{
printf("%d = %d + %d\n",n,pri[i],n-pri[i]);
break;
}
}
}
}
poj2262 Goldbach's Conjecture——筛素数的更多相关文章
- poj2262 Goldbach's Conjecture
poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下. #include<iostream> #include<cstdio> #inc ...
- [POJ2262] Goldbach’s Conjecture
Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48161 Accepted: ...
- poj 2262 Goldbach's Conjecture——筛质数(水!)
题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
一.Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...
- HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...
- Goldbach`s Conjecture(素筛水题)题解
Goldbach`s Conjecture Goldbach's conjecture is one of the oldest unsolved problems in number theory ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
随机推荐
- RESTful API设计的简单例子
代码承接简单服务器,修改 app.js const koa = require('koa'), app = new koa(), Router = require('koa-router'), rou ...
- MyBatis 的基本介绍及使用
一.简介 MyBatis 是支持定制化 SQL.存储过程以及高级映射的持久层框架(ORM).MyBatis 可以使用简单的 XML 或 注解用于配置和映射数据表,是将 POJO(Plain Old ...
- 用 Systemtap 统计 TCP 连接
转自: https://mp.weixin.qq.com/s?__biz=MzIxMjAzMDA1MQ==&mid=2648946009&idx=1&sn=3a0be2fe4f ...
- 一起看看 scrollHeight,clientHeight,offsetHeight,scrollTop是个啥
scrollHeight最终数值的组成: var scrollHeight = currentElementContent.height +currentElement.paddingTop+curr ...
- UVA - 514 Rails(栈模拟)
题目: 给出一个序列,问将1,2,3,4……按从小到大的顺序入栈,能否得到给出的序列. 思路: 用stack模拟就可以了. 当前的cnt如果小于a[i],就将cnt入栈,否则就判断栈顶是不是和a[i] ...
- MyBatis 中传递多个参数的 4 种方式
方式 1 :封装成对象入参 #{对应实体类的属性} //UserMapper.java 接口 /** * 多条件查询:根据用户名称(模糊查询)和用户角色查询用户列表(参数:对象入参) * @para ...
- Linux—Ubuntu14.0.5配置JAVA环境
1. 前往ORACLE官网下载最新版本的Java JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html,默认下载 ...
- 省市区json结构
[ { "label": "北京市", "value": "北京市", "children": [ ...
- Ubuntu挂载硬盘,修改卷标
Ubuntu挂载硬盘,修改卷标转载2016-03-06 17:03:21标签:ubuntu Ubuntu不像windows,硬盘插入电脑不会自动读取硬盘 数据,需要把硬盘挂载到文件夹上,然后才能访问硬 ...
- vue 刷新当前页面的时候重新调用新的cookie
data() { return{ AdminToken: this.getCookie('token'), } }, updated() { //刷新当前页面的时候重新调用新的cookie this. ...