题目链接:

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. 用jquery监听输入数字的变化

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  2. RGB-D数据集(SLAM的和行人检测的)

    移动机器人编程一般用mrpt,这个软件来做三维,里面封装了很多常用算法. http://www.mrpt.org/download-mrpt/ SLAM的数据集,其中包括机器人slam http:// ...

  3. ionic3.x angular4.x ng4.x 自定义组件component双向绑定之自定义计数器

    本文主要示例在ionic3.x环境下实现一个自定义计数器,实现后最终效果如图: 1.使用命令创建一个component ionic g component CounterInput 类似的命令还有: ...

  4. Python3.5 学习二十二

    回顾: 发送请求时:发送请求头和请求数据 request.META和request.request.body 响应请求时:响应头和响应返回数据 response.HEADER和response.bod ...

  5. Java正则表达式初学者使用法简介

    在Java中使用正则表达式的方法非常多,最简单的就是和字符串一起使用.对于Java正则表达式初学者,在String中有四个方法可以使用正则表达式,本文正是介绍这四个方法来使用正则表达式来处理文本数据. ...

  6. Select count(*)、Count(1)、Count(0)的区别和执行效率比较

    记得很早以前就有人跟我说过,在使用count的时候要用count(1)而不要用count(*),因为使用count(*)的时候会对所有的列进行扫描,相比而言count(1)不用扫描所有列,所以coun ...

  7. TmsTimeUtils 时间戳

    package com.sprucetec.tms.utils; import java.math.BigDecimal;import java.text.DateFormat;import java ...

  8. wp推送消息笔记

    最近想给应用添加推送消息,主要是toast消息,所以就打算去了解一下wp消息推送机制以及实现方法,过程中,查了许多资料,也遇到过一些问题,做完后,自己就做个小笔记,总结一下,好记性不如烂笔头嘛,以后可 ...

  9. css 的 conic-gradient 学习

    偶然间在微信公众号奇舞周刊上看到了这篇文章<CSS Painting API>,算是对 conic-gradient的初次见面. 后来有空的时候,百度搜了一下,看了这篇文章<CSS神 ...

  10. WebSocket集成XMPP网页即时通讯1:Java Web Project服务端/客户端Jetty9开发初探

    Web 应用的信息交互过程通常是客户端通过浏览器发出一个请求,服务器端接收和审核完请求后进行处理并返回结果给客户端,然后客户端浏览器将信息呈现出来,这种机制对于信息变化不是特别频繁的应用尚能相安无事, ...