文件名称:uva543
介绍说明--下载内容均来自于网络,请自行研究使用
題目 :
在1742年一個德國業餘數學家Christian Goldbach,他作了以下的猜測:
任何一個比4大的偶數一定能夠找到2個奇數的質數使其和相等。例如:
8=3+5(3和5都是奇數,且是質數)
20=3+17=7+13
42=5+37=11+31=13+29=19+23
你的任務就是寫一個程式來驗證他的猜測。
Input
輸入包含好幾筆測試資料,每筆資料1行,包含一個偶數的整數n(4 < n < 1000000)。
n=0代表輸入結束。
Output
對每筆輸入資料你應該要以 n = a + b 的形式輸出,其中 a、b都是奇數的質數。
如果有一組以上的 a、b,請輸出 b-a 最大的那組。
如果找不到這樣的 a、b,請輸出 Goldbach s conjecture is wrong.
解法 :
1. 先建立一個一為陣列,把奇數質數的格子設為 1,其餘設為 0 ,使用埃氏篩法得到質數
2. 判斷一為陣列,如果兩個為 1 的陣列相加等於輸入,輸出陣列位置,即為答案-Title: In 1742, a German amateur mathematician Christian Goldbach, he made the following guess: Any even larger than 4 will be able to find two odd primes it and equal. For example: 8 = 3+5 (3 and 5 are odd, and is a prime number) 20 = 3+17 = 7+13 42 = 5+37 = 11+31 = 13+29 = 19+23 Your task is to write a program to verify his guess. Input pen input contains several test data, each data row that contains an even integer n (4 < n < 1000000). n = 0 represents the input end. Output for each input data you should to n = a+ b output in the form in which a, b are odd primes. If there is more than one set of a, b, ba please output the set maximum. If you can not find such a, b, please output " Goldbach' s conjecture is wrong." Solution: 1. To set up a one array, the odd prime number grid is set to 1, and the rest is set to 0, using the sieve method to obtain Erichsen 2. judge a prime number in an array, the array is 1 if the sum of the two equal input and output array position,
在1742年一個德國業餘數學家Christian Goldbach,他作了以下的猜測:
任何一個比4大的偶數一定能夠找到2個奇數的質數使其和相等。例如:
8=3+5(3和5都是奇數,且是質數)
20=3+17=7+13
42=5+37=11+31=13+29=19+23
你的任務就是寫一個程式來驗證他的猜測。
Input
輸入包含好幾筆測試資料,每筆資料1行,包含一個偶數的整數n(4 < n < 1000000)。
n=0代表輸入結束。
Output
對每筆輸入資料你應該要以 n = a + b 的形式輸出,其中 a、b都是奇數的質數。
如果有一組以上的 a、b,請輸出 b-a 最大的那組。
如果找不到這樣的 a、b,請輸出 Goldbach s conjecture is wrong.
解法 :
1. 先建立一個一為陣列,把奇數質數的格子設為 1,其餘設為 0 ,使用埃氏篩法得到質數
2. 判斷一為陣列,如果兩個為 1 的陣列相加等於輸入,輸出陣列位置,即為答案-Title: In 1742, a German amateur mathematician Christian Goldbach, he made the following guess: Any even larger than 4 will be able to find two odd primes it and equal. For example: 8 = 3+5 (3 and 5 are odd, and is a prime number) 20 = 3+17 = 7+13 42 = 5+37 = 11+31 = 13+29 = 19+23 Your task is to write a program to verify his guess. Input pen input contains several test data, each data row that contains an even integer n (4 < n < 1000000). n = 0 represents the input end. Output for each input data you should to n = a+ b output in the form in which a, b are odd primes. If there is more than one set of a, b, ba please output the set maximum. If you can not find such a, b, please output " Goldbach' s conjecture is wrong." Solution: 1. To set up a one array, the odd prime number grid is set to 1, and the rest is set to 0, using the sieve method to obtain Erichsen 2. judge a prime number in an array, the array is 1 if the sum of the two equal input and output array position,
(系统自动生成,下载前可以参看下载内容)
下载文件列表
uva543\uva543#a.in.txt
......\uva543#a.out.txt
......\uva543#b.in.txt
......\uva543#b.out.txt
......\uva543_1101105324.cpp
......\uva543_1101105324.exe
......\uva543_readme.txt
uva543