UVa 686 Goldbach's Conjecture (II) (哥德巴赫猜想)
来源:互联网 发布:数据库编辑器有哪些 编辑:程序博客网 时间:2024/05/23 16:54
686 - Goldbach's Conjecture (II)
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=627
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 215. 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
610120
Sample Output
121
同这一题。
完整代码:
/*0.015s*/#include<cstdio>#include<cmath>const int maxn = 1 << 15;const int m = (int)sqrt(maxn);bool vis[maxn];inline void cal_prime(){int i, j;for (i = 2; i <= m; ++i)if (!vis[i])for (j = i * i; j < maxn; j += i)vis[j] = true;}int main(){cal_prime();int n, m, i, count;while (scanf("%d", &n), n){count = 0, m = n >> 1;for (i = 2; i <= m; ++i)if (!vis[i] && !vis[n - i])++count;printf("%d\n", count);}return 0;}
- UVa 686 Goldbach's Conjecture (II) (哥德巴赫猜想)
- UVa 543 Goldbach's Conjecture (素数&哥德巴赫猜想)
- POJ 2262 Goldbach's Conjecture 哥德巴赫猜想
- POJ 2262 Goldbach's Conjecture哥德巴赫猜想
- POJ 2262 Goldbach's Conjecture(哥德巴赫猜想)
- 【哥德巴赫猜想】LightOJ Goldbach`s Conjecture 1259
- 【哥德巴赫猜想】POJ Goldbach's Conjecture 2262
- NUC1090 Goldbach's Conjecture【哥德巴赫猜想 】
- HDOJ1397 Goldbach's Conjecture(哥德巴赫猜想)
- UVa 686 - Goldbach's Conjecture (II)
- POJ2262,Goldbach's Conjecture,哥德巴赫猜想水过
- LightOJ 1259 Goldbach`s Conjecture(证明哥德巴赫猜想)
- Lightoj1259——Goldbach`s Conjecture(哥德巴赫猜想)
- poj 2262 Goldbach's Conjecture 筛法 哥德巴赫猜想
- HDU - 1397 Goldbach's Conjecture(哥德巴赫猜想)
- POJ-2262 Goldbach's Conjecture 解题报告(数论) 哥德巴赫的猜想
- 7-3 Goldbach's Conjecture (哥德巴赫猜想)(30 分)
- UVa 543 - Goldbach's Conjecture
- java中小数的四舍六入和四舍五入
- alter index rebuild 与 rebuild online
- VC中类型的相互转化
- MongoDB学习笔记2--MongoDB数据库中数据的导入
- Leetcode: Trapping Rain Water
- UVa 686 Goldbach's Conjecture (II) (哥德巴赫猜想)
- 设计模式之适配器模式
- C#中ADO.NET连接数据库中的DbNull 与 null的区别
- Github执行git add -A 出现 LF will be replaced by CRLF in *
- 字符串匹配问题:KMP算法
- 十道大数据的题
- c++有关编译期和运行期的访问
- JBoss 系列三:使用4种方式部署应用到JBoss7/WildFly
- 十七道海量数据面试题