53-题目1440:Goldbach's Conjecture
2016-03-09 16:38
495 查看
http://ac.jobdu.com/problem.php?pid=1440
题目描述: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.
简而言之,给一个数N([4,2^15]),找出它的素数对,即要满足P1+P2=N,求N有多少这样的素数对。
#include<iostream> #include<fstream> using namespace std; #define MAX 105000 int PrimeNum(int n) //判断是否是素数,返回1表示是素数,0非素数 { int i; for (i = 2; i < n; i++) { if (n % i == 0) break; } if (i == n) return 1; else return 0; } int main() { int num, i, count, p1, p2; ifstream cin("data.txt"); while (cin >> num && num != 0) { count = 0; for (i = 3; i <= num / 2; i++) { p1 = i; p2 = num - i; if (PrimeNum(p1) && PrimeNum(p2)) //两个都是素数 { //cout << p1 << " " << p2 << endl; count++; } } cout << count << endl; } system("pause"); return 0; }
相关文章推荐
- 新浪SAE部署django博客
- 初识Golang
- [golang note] 匿名组合
- 我与小娜(30):AlphaGo赢了!
- ORA-01017: invalid username/password; logon denied
- alphago战胜李世石
- django mongoengine 判断mongoengine定义的字段类型
- 为网页添加logo图标
- Go一致性哈希库consistent
- Codeforces 86D. Powerful array (MO's Algorithm(区间查询的离线优化))
- golang中调用C
- golang中函数闭包遇到的坑
- django1.8 增加注册用户其他字段
- 李世石和AlphaGo人机围棋大赛
- Go语言中Restful模式与Routes路由框架
- Google 搜索命令
- CodeForces 630D-Hexagons!
- goto void
- Django入门
- HDU 3903 Trigonometric Function(数学定理)