题目链接:

https://cn.vjudge.net/problem/POJ-2262

题目描述:

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
 /*
题意描述
将一个数分成两个奇素数之和的形式,即c=a+b,如果有多种方案,输出b-a差值最大的 解题思路
打表,枚举查询
*/
#include<cstdio>
#include<cmath>
#include<cstring>
const int maxn=+;
bool isprim[maxn];
void makeprim(int n); int main()
{
makeprim(maxn);
int n,i;
//freopen("E:\\testin.txt","r",stdin);
while(scanf("%d",&n) == && n != ){
for(i=;i<=maxn;i++){
if(i& && isprim[i] && (n-i)& &&isprim[n-i]){
printf("%d = %d + %d\n",n,i,n-i);
break;
}
}
if(i == maxn+)
printf("Goldbach's conjecture is wrong.\n");
}
return ;
} void makeprim(int n){
memset(isprim,,sizeof(isprim));
isprim[]=isprim[]=;
int k=(int)sqrt(n+0.5);
for(int i=;i<=k;i++){
if(isprim[i]){
for(int j=i*;j<=n;j+=i)
isprim[j]=;
}
}
}

POJ 2262 Goldbach's Conjecture (打表)的更多相关文章

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

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

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

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

  3. POJ 2262 Goldbach's Conjecture 数学常识 难度:0

    题目链接:http://poj.org/problem?id=2262 哥德巴赫猜想肯定是正确的 思路: 筛出n范围内的所有奇质数,对每组数据试过一遍即可, 为满足b-a取最大,a取最小 时空复杂度分 ...

  4. POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)

    http://poj.org/problem?id=2262 题意: 哥德巴赫猜想,把一个数用两个奇素数表示出来. 思路:先用Eratosthenes筛法打个素数表,之后枚举即可. #include& ...

  5. poj 2262 Goldbach's Conjecture

    素数判定...很简单= =.....只是因为训练题有,所以顺便更~ #include<cstdio> #include<memory.h> #define maxn 50000 ...

  6. POJ 2262 Goldbach&#39;s Conjecture(素数相关)

    POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...

  7. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

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

  8. poj 2262【素数表的应用---判断素数】【哈希】

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

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

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

随机推荐

  1. CSS 基础 例子 定位及z-index

    position 属性指定了元素的定位类型. position 属性的四个值: static    不设置默认为该值,即没有定位,元素出现在正常的流中.不能使用top,bottom,left,righ ...

  2. Java学习--基本数据类型的定义和运算2

    例1 public class OperateDemo01{ public static void main(String args[]){ int num = 22 ; System.out.pri ...

  3. delphi IsIPAdress 非正则表达式验证IP的方法

    function IsIPAdress(const Value:String):Boolean; var n,x,i: Integer; Posi:Array[..]of Integer; Oktet ...

  4. QuartzNet使用

    quartz.config # You can configure your scheduler in either <quartz> configuration section # or ...

  5. 【推荐】介绍两款Windows资源管理器,Q-Dir 与 FreeCommander XE(比TotalCommander更易用的免费资源管理器)

    你是否也像我一样,随着硬盘.文件数量的增加,而感到对于文件的管理越来越乏力. 于是我试用了传说中的各种软件,包括各种Explorer外壳,或者第三方资源管理器. 最后我确定下来经常使用,并推荐给您的是 ...

  6. FastReport使用方法(C/S版)

    前言 这两天群里一直有群友问一些关于FastReport的问题,结合他们的问题,在这里做一个整理,有不明白的可以加 FastReport 交流群 群   号:554714044 工具 VS2017 + ...

  7. bower 安装后 jade 引用404问题

    这个问题困扰我接近2小时,这是我在stackoveflow 上面挖到的 原文地址:http://stackoverflow.com/questions/21821773/configure-node- ...

  8. 微信小程序如何跳转到另一个小程序

    微信小程序如何跳转到另一个小程序,要注意:在app.json文件里也要配置 navigateToMiniProgramAppIdList,如下图: "navigateToMiniProgra ...

  9. Postgres 的 deferrable

    仅 Postgres 支持 deferrable deferrable 即 推迟约束 一.定义字段时指定 定义:exam考试表里 subject_iddddd 字段关联了 subject 科目表的 i ...

  10. Shell - 简明Shell入门11 - 调用脚本(CallTheScript)

    示例脚本及注释 主脚本: CallTheScript.sh #!/bin/bash . ./11-subscript.sh # 调用其他脚本;注意点号"."和文件路径之间有一空格; ...