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. [AWS] EC2 & GPU

    Amazon Elastic Compute Cloud (Amazon EC2) EC 2的使用 机型的选择 经验谈 Ref: Amazon EC2 实例类型 实践派 搭建网站:MediaWiki ...

  2. [转载 ]五种常见的 PHP 设计模式

    五种常见的 PHP 设计模式 策略模式 策略模式是对象的行为模式,用意是对一组算法的封装.动态的选择需要的算法并使用. 策略模式指的是程序中涉及决策控制的一种模式.策略模式功能非常强大,因为这个设计模 ...

  3. RDD转换为DataFrame【反射/编程】

    写在前面 主要是加载文件为RDD,再把RDD转换为DataFrame,进而使用DataFrame的API或Sql进行数据的方便操作 简单理解:DataFrame=RDD+Schema 贴代码 pack ...

  4. Flume和Kafka完成实时数据的采集

    Flume和Kafka完成实时数据的采集 写在前面 Flume和Kafka在生产环境中,一般都是结合起来使用的.可以使用它们两者结合起来收集实时产生日志信息,这一点是很重要的.如果,你不了解flume ...

  5. GStreamer基础教程08 - 多线程

    摘要 GStreamer框架会自动处理多线程的逻辑,但在某些情况下,我们仍然需要根据实际的情况自己将部分Pipeline在单独的线程中执行,本文将介绍如何处理这种情况. GStreamer多线程 GS ...

  6. Spring MVC-从零开始-@RequestMapping结合@RequestParam (从HTTP键值对中取值,作用于函数参数)

    1.@RequestParam 注解使用的时候可以有一个值,也可以没有值:如果请求参数和处理方法参数的名称一样的话,@RequestParam 注解的 value 这个参数就可省掉了:@Request ...

  7. Save&Load--Unity存档读档的学习总结

    存档与读档功能 举例: 传统RPG游戏(仙剑.空之轨迹): 1.角色信息(生命值,等级) 2.道具信息(装备,药品) 3.场景信息(场景名称.角色坐标) 4.事件信息(任务相关) 关卡类游戏:关卡的通 ...

  8. dependencies 与 dependencyManagement 区别

    dependencies 即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)dependencyManagement 里只是声明依赖,并不实现引入,因此子项目需要显示的声明 ...

  9. SUSE Ceph 快速部署 - Storage6

    学习 SUSE Storage 系列文章 (1)SUSE Storage6 实验环境搭建详细步骤 - Win10 + VMware WorkStation (2)SUSE Linux Enterpri ...

  10. 如何设置eclipse自动提示功能

    1.Window --> preferences 2.java --> Editor --> Content Assist 3.将Auto activation triggers f ...