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

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

 

 
提交地址POJ2262
 

 
题解 :
怎么又是水题...
先筛法出素数;
然后暴力判断;
 

 
Code
 #include <iostream>
#include <cstdio>
using namespace std; bool isprime[]; //1 -> 合数, 0 -> 质数 int main()
{
isprime[] = isprime[] = ;
for (register int i = ; i <= ; i ++)
{
if (isprime[i]) continue;
for (register int j = i ; j <= /i ; j ++)
isprime[i*j] = ;
} int n;
while (scanf("%d", &n) != EOF)
{
if (n == ) return ;
for (register int i = ; i <= n ; i ++)
{
if (!isprime[i] and !isprime[n-i])
{
printf("%d = %d + %d\n", n, i, n-i);
break;
}
}
} }

[POJ2262] Goldbach’s Conjecture的更多相关文章

  1. poj2262 Goldbach's Conjecture

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

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

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

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

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

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

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

  5. Goldbach's Conjecture

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

  6. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

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

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

  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. 搜索入门练习题9 LETTERS 题解

    题目出处:<信息学奥赛一本通>第五章上机练习1 或者 POJ1154 题目描述 给出一个 \(R\times S\) 的大写字母矩阵,一开始你所处的位置在左上角,你可以向上下左右四个方向移 ...

  2. Android mmap 文件映射到内存介绍

    本文链接: Android mmap 文件映射到内存介绍 Android开发中,我们可能需要记录一些文件.例如记录log文件.如果使用流来写文件,频繁操作文件io可能会引起性能问题. 为了降低写文件的 ...

  3. C++输入输出常用格式(cin,cout,stringstream)

    输入格式 1.cin>>a; 最基本的格式,适用于各种类型.会过滤掉不可见字符例如空格,TAB,回车等 2.cin>>noskipws>>ch[i]; 使用了 no ...

  4. Oracle之select

    坚持

  5. HBase导入数据同时与Phoenix实现同步映射

    1.HDFS上数据准备 2019-03-24 09:21:57.347,869454021315519,8,1 2019-03-24 22:07:15.513,867789020387791,8,1 ...

  6. DOM之事件(二)

    今天详细讲解JavaScript中的常用事件类型和功能. 一 鼠标事件 1,  click:点击事件 等同于mousedown+mouseup,不管这两个事件间隔多久,都会触发一次click事件. 2 ...

  7. 了解一下Java SPI的原理

    了解一下Java SPI的原理 1 为什么写这篇文章? 近期,本人在学习dubbo相关的知识,但是在dubbo官网中有提到Java的 SPI,这个名词之前未接触过,所以就去看了看,感觉还是有很多地方有 ...

  8. Selenium+python上传本地文件或者图片

    基于input标签的,有属性type = file: 首先定位到点击上传的元素(input)然后直接使用send_keys()将文件在本地的路径传进去 代码如下(例子来源于本页面上传图片和文件): f ...

  9. Excel自定义格式参数

    一.自定义格式 方式一:代码结构组成代码分为四个部分,中间用“:”号分隔,具体如下:正数格式:负数格式:零格式:文本格式 两个代码部分,则第一部分用于正数和零和文本,第二部分用于负数 一个代码部分,则 ...

  10. 使用Fedora8 iso开发环境开发gtk3跨Linux多版本桌面应用

    原文: https://bbs.otherhill.com/index.php/topic/show/82 gtk3 demo在/usr/local/gtk3demo 目录下 cd /usr/loca ...