poj2262 Goldbach's Conjecture
用欧拉筛把素数筛出来,再枚举一下。
#include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
#define N 1000001
int n,v[N],pri[N],cct; bool is[N];
int main(){
for(int i=;i<N;++i){
if(!v[i]) is[v[i]=pri[++cct]=i]=;
for(int j=;j<=cct;++j){
if(pri[j]>i||pri[j]*i>=N) break;
v[pri[j]*i]=pri[j];
}
}
while(scanf("%d",&n)){
if(!n) return ;
bool flag=;
for(int i=;i<=cct&&flag;++i)
if(is[i]&&is[n-i])
printf("%d = %d + %d\n",n,i,n-i),flag=;
if(flag) puts("Goldbach's conjecture is wrong.");
}return ;
}
poj2262 Goldbach's Conjecture的更多相关文章
- [POJ2262] Goldbach’s Conjecture
Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48161 Accepted: ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- poj2262 Goldbach's Conjecture——筛素数
题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- 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 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Goldbach's Conjecture(哥德巴赫猜想)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
随机推荐
- 使用Editplus和Dev C++配置C++的编译运行环 境
或许大家会有疑问,为何不直接使用VC;VS;或Dev这些IDE呢?何必舍近求远.主要是因为写程序这么多年来已经习惯了Editplus,包括他的快捷键,语法自动完成,语法提示等等,Editplus用了这 ...
- JS选中清空
var inputArray = document.getElementsByTagName("input"); var strArray = []; ; i < input ...
- LeetCode - Employees Earning More Than Their Managers
Description: The Employee table holds all employees including their managers. Every employee has an ...
- ELK基础学习
第壹部分:Elasticsearch 一 .Elasticsearch增删改查1.数据写入:HTTP method:POSTURL:http://127.0.0.1:9200/index-docs-n ...
- Linux Netfilter注册钩子点
注册钩子点首先要包含响应的头文件,因为这应该已经属于对kernel的编程了. #include <linux/module.h> #include <linux/kernel.h&g ...
- ansible批量验证密码
author: headsen chen date: 2018-08-31 20:45:49 综合比较salt-ssh,ansible .sshpass等批量验证100台机器的密码,最好推荐用ans ...
- ionic开发过程中遇到的一些坑!
总结一些:在使用 ionic 开发过程中所遇到的问题. 问题一:Cannot find module '@ionic/app-scripts' 描述:使用 ionic start 项目的时候,项目安装 ...
- 网络下载功能实现(downloader ) ---- HTML5+
模块:downloader Downloader模块管理网络文件下载任务,用于从服务器下载各种文件,并支持跨域访问操作.通过plus.downloader获取下载管理对象.Downloader下载使用 ...
- 【JavaScript算法】---插入排序
一.什么叫做插入排序法 有一个已经有序的数据序列,要求在这个已经排好的数据序列中插入一个数,但要求插入后此数据序列仍然有序,这个时候就要用到一种新的排序方法——插入排序法 二.核心 插入排序的基本操作 ...
- 利用Linux系统生成随机密码的8种方法
Linux操作系统的一大优点是对于同样一件事情,你可以使用高达数百种方法来实现它.例如,你可以通过数十种方法来生成随机密码.本文将介绍生成随机密码的十种方法. 1. 使用SHA算法来加密日期,并输出结 ...