HDU 1397 Goldbach's Conjecture
2012-08-12 11:15
387 查看
Goldbach's Conjecture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3322 Accepted Submission(s): 1213
[align=left]Problem Description[/align]
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2.
This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of
all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.
A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are interested in the number of essentially different pairs and therefore you should not count (p1, p2)
and (p2, p1) separately as two different pairs.
[align=left]Input[/align]
An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 2^15. The end of the input is indicated by a number 0.
[align=left]Output[/align]
Each output line should contain an integer number. No other characters should appear in the output.
[align=left]Sample Input[/align]
6 10 12 0
[align=left]Sample Output[/align]
1 2 1
思路:这题就是求一个偶数可以有多少对素数表示。
我是用暴力的方式解决的。
AC代码:
#include<iostream> using namespace std; bool prime[40000]; void init( ) { int i,j; for(i=0;i<=40000;i++) prime[i]=1; for (i=2;i<=200;i++) if(prime[i]) for(j=2;j*i<=40000;j++) prime[i*j]=0; } int main() { int n,i,num; init(); while(scanf("%d",&n)!=EOF&&n!=0) { num=0; for(i=2;i<=n/2;i++) if(prime[i]&&prime[n-i])num++; printf("%d\n",num); } return 0; }
相关文章推荐
- HDU - 1397 Goldbach's Conjecture
- HDU 1397 Goldbach's Conjecture(素数判断)
- hdu 1397 Goldbach's Conjecture
- HDU 1397 Goldbach's Conjecture(素数打表)
- POJ 2909 && HDU 1397 Goldbach's Conjecture(数论)
- hdu 1397 Goldbach's Conjecture
- HDOJ 1397:Goldbach's Conjecture 哈希加筛选法求素数
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
- HDOJ 1397 Goldbach's Conjecture [爱沙托散筛法求素数]
- hdoj 1397 Goldbach's Conjecture (大数素数打表)
- hdu Goldbach's Conjecture
- HDOJ-1397-Goldbach's Conjecture 解题报告
- 杭电 HDU ACM 1397 Goldbach's Conjecture
- POJ 2262-Goldbach's Conjecture(素数筛)
- UVa 543 Goldbach's Conjecture (素数&哥德巴赫猜想)
- POJ 2262 Goldbach's Conjecture(素数表)
- POJ 2262 Goldbach's Conjecture (求解素数的一般筛和线性筛)
- poj-2262 Goldbach's Conjecture
- POJ Goldbach's Conjecture(素数筛~欧拉筛法)
- POJ-2909-Goldbach's Conjecture