Goldbach's Conjecture
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 36877   Accepted: 14119

Description

In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:

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

The input will contain one or more test cases.

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

For
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

Ulm Local 1998
思路:筛选法弄出素数,然后a从最小素数循环,遇到结果就直接输出。注意C语言比C++速度

#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的更多相关文章

  1. poj2262 Goldbach's Conjecture

    poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下. #include<iostream> #include<cstdio> #inc ...

  2. [POJ2262] Goldbach’s Conjecture

    Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48161   Accepted: ...

  3. POJ2262问题描述

    Goldbach's Conjecture   Description In 1742, Christian Goldbach, a German amateur mathematician, sen ...

  4. poj2909 || poj2262

    #include <stdio.h> #include <stdlib.h> #include<math.h> int isPri(int a, int b) { ...

  5. 筛法求质——poj2262&2909

    这两道题都是哥赫巴德猜想的内容.基本的技术点都是在一个很大的数字范围里面求质数.直接判断两个数是不是质数,这种方法虽然可行但是还是很慢的.所以这两题我们使用打表! 而建立质数表的方法就是筛法求质,速度 ...

  6. [暑假集训--数论]poj2262 Goldbach's Conjecture

    In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...

  7. poj2262 Goldbach's Conjecture——筛素数

    题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...

  8. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  9. POJ推荐50题

    此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...

随机推荐

  1. 深入super,看Python如何解决钻石继承难题

    1.   Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通方法和super方法 假设Base是基类 class Base(object): def __init_ ...

  2. VSCode

    下载: 打开终端控制器 wget http://download.microsoft.com/download/0/D/5/0D57186C-834B-463A-AECB-BC55A8E466AE/V ...

  3. python高级编程技巧

    由python高级编程处学习 http://blog.sina.com.cn/s/blog_a89e19440101fb28.html Python列表解析语法[]和生成 器()语法类似 [expr  ...

  4. WebService- 使用 CXF 开发 SOAP 服务

    选框架犹如选媳妇,选来选去,最后我还是选了“丑媳妇(CXF)”,为什么是它?因为 CXF 是 Apache 旗下的一款非常优秀的 WS 开源框架,具备轻量级的特性,而且能无缝整合到 Spring 中. ...

  5. 初学者学Java设计模式(一)------单例设计模式

    单例设计模式 单例设计模式是指一个类只会生成一个对象,优点是他可以确保所有对象都访问唯一实例. 具体实现代码如下: public class A { public static void main(S ...

  6. (转)通过在 Page 指令或 配置节中设置 validateRequest=false 可以禁用请求验证

    通过在 Page 指令或 配置节中设置 validateRequest=false 可以禁用请求验证 说明:   请求验证过程检测到有潜在危险的客户端输入值,对请求的处理已经中止.该值可能指示危及应用 ...

  7. jquery悬停tab

    <style> *{ margin:0; padding:0;} body { font:12px/19px Arial, Helvetica, sans-serif; color:#66 ...

  8. 用C++写出hanoi

    汉诺塔(港台:河內塔)是根据一个传说形成的數學问题有三根杆子A,B,C.A杆上有N个(N>1)穿孔圆盘,盘的尺寸由下到上依次变小.要求按下列规则将所有圆盘移至C杆:-每次只能移动一个圆盘-大的盘 ...

  9. [转]C++学习心得

    1.把C++当成一门新的语言学习: 2.看<Thinking In C++>: 3.看<The C++ Programming Language>和<Inside The ...

  10. Oracle11g R2学习系列 之十 解决EM不能用

    不知道是什么原因https://localhost:1158/em,今天突然就不能用了.做了好多搜索也没有解决.现象是在services.msc中,不能重启OracleDBConsole服务,提示: ...