POJ 2262 Goldbach's Conjecture (打表)

时间:2021-10-11 23:48:28

题目链接:

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&&num;39&semi;s Conjecture&lpar;素数筛选法&rpar;

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

  2. poj 2262 Goldbach&&num;39&semi;s Conjecture——筛质数&lpar;水!&rpar;

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

  3. POJ 2262 Goldbach&&num;39&semi;s Conjecture 数学常识 难度&colon;0

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

  4. POJ 2262 Goldbach&&num;39&semi;s Conjecture(Eratosthenes筛法)

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

  5. poj 2262 Goldbach&&num;39&semi;s Conjecture

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

  6. POJ 2262 Goldbach&amp&semi;&num;39&semi;s Conjecture&lpar;素数相关&rpar;

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

  7. Poj 2262 &sol; OpenJudge 2262 Goldbach&&num;39&semi;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&&num;39&semi;s Conjecture (素数判定)

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

随机推荐

  1. C语言共用体、大小端、枚举

    1.共用体和结构体的相同和不同 (1)相同点就是操作语法几乎相同.(2)不同点是本质上的不同.struct是多个独立元素(内存空间)打包在一起:union是一个元素(内存空间)的多种不同解析方式. # ...

  2. java读取输入流

    java读取输入流两种 private static byte[] readStream(InputStream in){ if(in==null){ return null; } byte[] bu ...

  3. 【caffe】三种文件类别:solver&comma;model和weights

    @tags: caffe 文件类别 solver文件 是一堆超参数,比如迭代次数,是否用GPU,多少次迭代暂存一次训练所得参数,动量项,权重衰减(即正则化参数),基本的learning rate,多少 ...

  4. Java for LeetCode 027 Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  5. 建模算法(四)&mdash&semi;&mdash&semi;动态规划

    其实我们对着规划接触的最多最熟悉,简单来说就是一个递归问题,递归问题简单的在的地方,编程实现的难度下降了,难的地方是如何构造递归,不好的地方是资源的浪费,但是有些地方编程实现的简单的优势可以无视掉他的 ...

  6. svn 安装与设置

    Subversion可以通过网络访问它的版本库,从而使用户可以在不同的电脑上使用.一定程度上可以说,允许用户在各自的地方修改同一份数据是促进协作. 运行Subversion服务器需要首先要建立一个版本 ...

  7. Splay树再学习

    队友最近可能在学Splay,然后让我敲下HDU1754的题,其实是很裸的一个线段树,不过用下Splay也无妨,他说他双旋超时,单旋过了,所以我就敲来看下.但是之前写的那个Splay越发的觉得不能看,所 ...

  8. 极端气候频现 五款开发天气预报应用的API

    http://www.csdn.net/article/2014-02-07/2818322-weather-forecast-api-for-developing-apps

  9. 《java入门第一季》之HashSet小案例:获取10个1至20的随机数,要求随机数不能重复

    这是基于HashSet集合的唯一性. /*  * 编写一个程序,获取10个1至20的随机数,要求随机数不能重复.  *   * 分析:  * A:创建随机数对象  * B:创建一个HashSet集合 ...

  10. usdt节点启动慢和队列深度超出了范围问题

    usdt节点启动慢和队列深度超出了范围问题 usdt的连接节点报错Work queue depth exceeded(队列深度超出了范围)大概是什么问题?重启了几次节点都不行队列深度超出了范围,估计是 ...