Goldbach's Conjecture
2015-09-28 12:39
633 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1397
网选赛给虐哭了,赶紧刷刷水题找找信心。
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5408 Accepted Submission(s): 2082
Problem Description
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.
Input
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.
Output
Each output line should contain an integer number. No other characters should appear in the output.
Sample Input
Sample Output
AC之路,我选择坚持~~
网选赛给虐哭了,赶紧刷刷水题找找信心。
Goldbach's Conjecture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5408 Accepted Submission(s): 2082
Problem Description
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.
Input
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.
Output
Each output line should contain an integer number. No other characters should appear in the output.
Sample Input
6 10 12 0
Sample Output
1 2 1
#include <cstdio> #include <iostream> using namespace std; int prim[40010]; void get_prim(){ fill(prim,prim+40000,1); for(int i=2;i*i<40000;i++) { int x=i*i; for(;x<40000;x+=i) prim[x]=0; } } int main() { int n; get_prim(); while(scanf("%d",&n)&&n){ int ans=0; for(int i=2;i<=n/2;i++){ if(prim[n-i]&&prim[i])ans++; } printf("%d\n",ans); } }
AC之路,我选择坚持~~
相关文章推荐
- go语言 获取post方式json
- 结构化视角看django
- Go语言自己实现的异步小log程序.
- hdu 5318 The Goddess Of The Moon(矩阵二分幂优化dp)
- django inclusion_tag
- mongo 启动
- Google APAC 2016 学习
- [algorithm][Reprint&summary]随机梯度下降法
- django admin 报错没有发现 table
- 在genymotion 模拟器中安装google service的方法
- django复习笔记3:实战
- #include&lt;algorithm&gt;里的函…
- ant colony algorithm && decision tree
- GOF23 设计模式之 代理模式
- google zxing编译
- GOF23 设计模式之 适配器模式
- Django添加Last-Modified和ETag
- gonna, gotta, wanna
- MMD_3b_StreamAlgorithms
- AlgorithmsI Programming Assignment 1: Percolation