POJ 2262 Goldbach's Conjecture 数学常识 难度:0
题目链接: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的更多相关文章
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- poj 2262 Goldbach's Conjecture——筛质数(水!)
题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
http://poj.org/problem?id=2262 题意: 哥德巴赫猜想,把一个数用两个奇素数表示出来. 思路:先用Eratosthenes筛法打个素数表,之后枚举即可. #include& ...
- poj 2262 Goldbach's Conjecture
素数判定...很简单= =.....只是因为训练题有,所以顺便更~ #include<cstdio> #include<memory.h> #define maxn 50000 ...
- POJ 2262 Goldbach's Conjecture(素数相关)
POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- POJ 1062 昂贵的聘礼 最短路 难度:0
http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...
随机推荐
- Nginx基本配置备忘
原文:http://www.open-open.com/lib/view/open1482477873078.html Nginx 配置 在了解具体的Nginx配置项之前我们需要对于Nginx配置文件 ...
- vi编辑器简单应用(摘抄)
摘抄于 vi编辑器的使用 (2) (3) 1 vi编辑器的基本使用 1.1 vi的启动 打开: $ vi example.c 只读打开 $ vi –R example.c 1.2 vi的工作模式 1. ...
- C语言 常用单词
main 主要的 printf(print format)格式输出 include , return ,if ,else ,switch ,case 机箱:案 ...
- Mvc4_ActionLink跟@RenderBody ,@RenderPage
. @Html.ActionLink("该链接要显示的文字A","对应的控制器方法B");会生成:<a href="C/B">A ...
- java 导入包
导入包 问题:类名冲突时,要如何解决. 解决:sun提供导入包语句让我们解决该问题. 导入包语句的作用:简化书写. 导入包语句的格式:import 包名.类名;(导入xxx包的XX类) 导入包语句的细 ...
- mysql5.7主从复制
1.简介 1.1主从复制 是指建立一个和主数据库完全一样的数据库环境,称为从数据库:主数据库一般是实时的业务数据库,从数据库的作用和使用场合一般有几个: 一是作为后备数据库,主数据库服务器故障后,可切 ...
- robotframework笔记24
侦听器接口 机器人框架有一个侦听器接口,可以用于接收 对测试执行通知. 示例用法包括 外部测试监控,测试失败时发送邮件消息, 与其他系统进行通信. 侦听器API版本3也使得 它可以修改测试在测试执行和 ...
- 《javascript高级程序设计》 第23章 离线应用与客户端存储
23.1 离线检测23.2 应用缓存23.3 数据存储 23.3.1 Cookie 23.3.2 IE 用户数据 23.3.3 Web 存储机制 23.3.4 IndexedDB 23.1 离线检 ...
- 转 http://www.5icool.org/a/201106/a654.html CSS开发中常用的公用样式
overflow:hidden 隐藏溢出 一.自己总结的公用样式解析 html, body, div, p, ul, li, dl, dt, dd, h1, h2, h3, h4, h5, h6, f ...
- 笔记7:winfrom的一些知识点(一)
一.MDI窗体 private void 添加窗体ToolStripMenuItem_Click(object sender, EventArgs e) { Form2 frm1 = new Form ...