| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3587 人关注过本帖
标题:[求助]一个偶数表示两个奇数之和。
只看楼主 加入收藏
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
 问题点数:0 回复次数:40 
[求助]一个偶数表示两个奇数之和。

Goldbach's Conjecture
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

搜索更多相关主题的帖子: 偶数 之和 Euler 奇数 conjecture 
2006-11-05 16:27
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized

该学习了。。。
2006-11-05 16:29
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
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.
If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized
这里的规律是什么呀?

该学习了。。。
2006-11-05 16:40
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

纠正一下:应该是一个偶数表示成为两个质数之和(num=a+b).当有很多组表示时,取使得b-a取到最大的那组.

所以比较简单:
直接a从3开始找(刚开始判断num!=4,若为4,直接2+2).只要a,num-a都是质数,则结束循环.否则a+=2,循环结束条件为(a<num/2);


倚天照海花无数,流水高山心自知。
2006-11-05 16:40
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

老感觉是ACM里的题目,这些是楼主老师弄来的题目?
顺便问一下,楼主是学计算机的?大几?


倚天照海花无数,流水高山心自知。
2006-11-05 16:42
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
呵呵!原来是质数之和啊!但是怎样判断一个数十质数啊?
直接a从3开始找(刚开始判断num!=4,若为4,直接2+2).只要a,num-a都是质数,则结束循环.否则a+=2,循环结束条件为(a<num/2);
这句话我没有理解!麻烦你再讲的仔细一些!谢谢了!

该学习了。。。
2006-11-05 16:45
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
呵呵!我是大一的,这些确实都是ACM的题,我学的是软件专业!才学C语言不久!

该学习了。。。
2006-11-05 16:47
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
哪个大学ACM的.
我来解释下:
其实也蛮简单的,如果是4,那只有一种情况那就是4=2+2.
所以可以直接在3开始,a+=2,是因为只有奇数才有可能是质数.要求b-a最大,所以只要a最小,那么b-a就会最大.

质数:只能整除1和本身的整数.(1不是质数)

倚天照海花无数,流水高山心自知。
2006-11-05 16:56
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
6 &lt;= n &lt; 1000000取值范围已经有了,所以不用判断是不是4的情形了!

该学习了。。。
2006-11-05 16:58
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
哈工大的

该学习了。。。
2006-11-05 17:02
快速回复:[求助]一个偶数表示两个奇数之和。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018352 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved