1.Link:

http://poj.org/problem?id=2262

http://bailian.openjudge.cn/practice/2262

2.Content:

Goldbach's Conjecture
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 37791   Accepted: 14536

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

3.Method:

筛素数法

4.Code:

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring> #define MAX_NUM 1000000 using namespace std; int main()
{
//freopen("D://input.txt","r",stdin); int i,j; bool * arr_prime = new bool[MAX_NUM + ]; for(i = ; i <= MAX_NUM; i += ) arr_prime[i] = true;
for(i = ; i <= MAX_NUM; i += ) arr_prime[i] = false;
arr_prime[] = true; int sqrt_mn = sqrt(MAX_NUM);
for(i = ; i <= sqrt_mn; i += )
{
if(arr_prime[i])
{
for(j = i + i; j <= MAX_NUM; j += i) arr_prime[j] = false;
}
} int a;
cin >> a; while(a != )
{ if(a % == && arr_prime[a - ])
{
cout << a << " = " << "" << " + " << (a - ) << endl;
}
else
{
for(i = ; i <= a / ; i += )
{
if(arr_prime[i] && arr_prime[a - i])
{
cout << a << " = " << i << " + " << (a - i) << endl;
break;
}
}
} cin >> a;
} return ;
}

5.Reference:

http://blog.csdn.net/liukehua123/article/details/5482854

Poj 2262 / OpenJudge 2262 Goldbach's Conjecture的更多相关文章

  1. Poj 2662,2909 Goldbach's Conjecture (素数判定)

    一.Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard ...

  2. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  3. poj 2262 Goldbach's Conjecture——筛质数(水!)

    题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...

  4. POJ 2262 Goldbach's Conjecture (打表)

    题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...

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

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

  6. Goldbach’s Conjecture(信息学奥赛一本通 1622)

    [题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=1 ...

  7. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  8. HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...

  9. Goldbach's Conjecture(哥德巴赫猜想)

    Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

随机推荐

  1. Android学习笔记之百度地图

    步行路线搜索及RouteOverlay 方式与驾车路线搜索类似,只需将mMKSearch.drivingSearch(null, start, null, end)修改为mMKSearch.walki ...

  2. asp.net mvc控制器动作体返回ImageResult,可作验证码

    public ActionResult Img() { // 获取博客园空间顶部的banner图片 WebRequest req = WebRequest.Create("http://sp ...

  3. [Javascript] IO Functor

    IO functor doesn't like Maybe(), Either() functors. Instead of get a value, it takes a function. API ...

  4. lucene_indexWriter说明、索引库优化

    IndexWriter Hibernate的SessionFactory 在Hibernate中.一般保持一个数据库就仅仅有一个SessionFactory.由于在SessionFactory中维护二 ...

  5. ABAP FIELD-SYMBOLS 有大作用- 将没有可改参数的增强出口变得也能改主程序的值了

    看下图代码: report  z_xul_test2 中 定义了 全局变量 G_DATA1 , 分别调用了 z_xul_tes1 中的 form  和 function zbapi_test , 这两 ...

  6. java后端模拟表单提交

    代码可实现文本域及非文本域的处理 请求代码: /** * 上传 * * @param urlStr * @param textMap * @param fileMap * @return */ pub ...

  7. MySQL Troubleshoting:Waiting on query cache mutex 腾讯数据库工程师:幕南风

    http://blog.itpub.net/26515977/viewspace-1208188/           今天被MySQL Query Cache 炕了.线上大量 Waiting on ...

  8. ptrace x64 转

    #include <sys/ptrace.h> #include <sys/types.h> #include <sys/wait.h> #include < ...

  9. 高级进程间通信之基于STREAMS的管道

    基于STREAMS的管道(简称STREAMS管道,STREAMS pipe)是一个双向(全双工)管道.单个STREAMS管道就能向父.子进程提供双向的数据流. 将http://www.cnblogs. ...

  10. iframe自适应高度的多种方法方法小结

    对于自适应高度的代码有很多,可效率什么的考虑进来好代码就不多见了,不过思路倒是差不多的  不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 ifram ...