poj2262
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 36877 | Accepted: 14119 |
Description
Every even number greater than 4 can be
written as the sum of two odd prime numbers.
For example:
8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.
Today it is still unproven whether the conjecture is right. (Oh
wait, I have the proof of course, but it is too long to write it on the
margin of this page.)
Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.
Input
Each test case consists of one even integer n with 6 <= n < 1000000.
Input will be terminated by a value of 0 for n.
Output
each test case, print one line of the form n = a + b, where a and b are
odd primes. Numbers and operators should be separated by exactly one
blank like in the sample output below. If there is more than one pair of
odd primes adding up to n, choose the pair where the difference b - a
is maximized. If there is no such pair, print a line saying "Goldbach's
conjecture is wrong."
Sample Input
8
20
42
0
Sample Output
8 = 3 + 5
20 = 3 + 17
42 = 5 + 37
Source
#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAXN 1000001
bool vis[MAXN]; int main()
{
//筛选法挑选素数
memset(vis,,sizeof(vis));
for(int i = ;i<(int)sqrt((double)MAXN);i++)
{
if(!vis[i])
{
for(int j=i*i ; j<MAXN;j+=i)
vis[j]=;
}
}
int n;
while(scanf("%d",&n)!=EOF&&n!=)
{
int a = ;
for(;a<n;a+=)
{
if(!vis[(n-a)]&&!vis[a])
{
printf("%d = %d + %d\n",n,a,n-a);
break;
}
}
}
return ;
}
快些。
poj2262的更多相关文章
- 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: ...
- POJ2262问题描述
Goldbach's Conjecture Description In 1742, Christian Goldbach, a German amateur mathematician, sen ...
- poj2909 || poj2262
#include <stdio.h> #include <stdlib.h> #include<math.h> int isPri(int a, int b) { ...
- 筛法求质——poj2262&2909
这两道题都是哥赫巴德猜想的内容.基本的技术点都是在一个很大的数字范围里面求质数.直接判断两个数是不是质数,这种方法虽然可行但是还是很慢的.所以这两题我们使用打表! 而建立质数表的方法就是筛法求质,速度 ...
- [暑假集训--数论]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题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- POJ推荐50题
此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...
随机推荐
- POJ2367 Genealogical tree (拓扑排序)
裸拓扑排序. 拓扑排序 用一个队列实现,先把入度为0的点放入队列.然后考虑不断在图中删除队列中的点,每次删除一个点会产生一些新的入度为0的点.把这些点插入队列. 注意:有向无环图 g[] : g[i] ...
- c语言else匹配问题
#include <stdio.h> #include <stdlib.h> //实现 依次输入三个递增的数 然后正确输出 //为什么得不到我们想要的结果呢 这就是else匹配 ...
- poj 2112 Optimal Milking (二分图匹配的多重匹配)
Description FJ has moved his K ( <= K <= ) milking machines <= C <= ) cows. A ..K; the c ...
- LDAP协议介绍
LDAP协议基础概念 1. 从用途上阐述LDAP,它是一个存储静态相关信息的服务,适合"一次记录多次读取".经常使用LDAP服务存储的信息: 公司的物理设备信息(如打印机,它的I ...
- [RxJS] Handling Multiple Streams with Merge
You often need to handle multiple user interactions set to different streams. This lesson shows hows ...
- 用递归翻转一个栈 Reverse a stack using recursion
明白递归语句之前的语句都是顺序运行,而递归语句之后的语句都是逆序运行 package recursion; import java.util.Stack; public class Reverse_a ...
- 转载:android——eclipse如何去除Ctrl+shift+R组合键查找到的.class文件
转载自:http://blog.csdn.net/virgilli/article/details/22500409 AS里面的build文件下一堆的.class 文件,当你要定位资源文件的时候,有些 ...
- CSS 盒子模型(转)
CSS中, Box Model叫盒子模型(或框模型),Box Model规定了元素框处理元素内容(element content).内边距(padding).边框(border) 和 外边距(marg ...
- 表格table常见的边框设置和初步的立体效果
做网页时经常会遇到表格,常见的表格如下: <style type="text/css"> .tbtest0 { width:500px; height:200px; b ...
- hdu1054 树状dp
B - 树形dp Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:10000KB 64bit ...