题目链接:

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. excel查找某一列的值在、不在另一列中

    统计中遇到找出一列的值不在另一列的需求: 找出A列中不在B列的值 方法如下: 使用countif函数 比如找出A列中不在B列的值: 在C1中输入 COUNTIF(B:B,A1) 下拉单元格,在首行添加 ...

  2. Java学习---- 数组的引用传递

    1. public class ArrayRefDemo01{ public static void main(String args[]){ int temp[] = {1,3,5} ; // 利用 ...

  3. DXP快捷键记录(红色为经常用到的)

    dxp快捷键 1.设计浏览器快捷键:鼠标左击                         选择鼠标位置的文档鼠标双击                         编辑鼠标位置的文档鼠标右击   ...

  4. 初次见识结构体与map的区别

    题目  http://vjudge.net/contest/view.action?cid=51142#problem/G 自己做的结构体 #include <iostream>#incl ...

  5. easyUi DataGrid 显示日期列,时间为空也可,的正常显示,及普通居中列情况

    $('#tt').datagrid({                url: '@Url.Content("~/kpi/FindList")',                w ...

  6. Java 学习的几个基础实验(Learn by doing)

    0 引子 不少情况下,学生连开发环境都搭建不好,有了实验楼,这个问题基本就解决了. 实验楼是国内首家IT在线实训平台,拥有最丰富的计算机在线实验课,而且全部免费.创业团队对师生的服务非常贴心细致. 1 ...

  7. 利用 TFLearn 快速搭建经典深度学习模型

      利用 TFLearn 快速搭建经典深度学习模型 使用 TensorFlow 一个最大的好处是可以用各种运算符(Ops)灵活构建计算图,同时可以支持自定义运算符(见本公众号早期文章<Tenso ...

  8. Django:model中的ForeignKey理解

    有两个数据模型栏目模型和文章模型ArticleColumn和ArticlePost ArticleColumn: class ArticleColumn(models.Model): # 用户与栏目是 ...

  9. 类库中使用WPF 资源文件

    1.类库的 后缀.csproj文件,第一个<PropertyGroup>中加入下面代码 <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-b ...

  10. 异常处理,约束,MD5加密日志处理

    程序运行过程中产生的错误, 不正常 def chufa(a, b): try: # 尝试执行xxx代码 ret = a/b # 如果这里出现了错误. 异常. 系统内部会产生一个异常对象. 系统会把这个 ...