Poj_2262 Goldbach's Conjecture(筛法求素数)
来源:互联网 发布:深爱的女孩 网络歌手 编辑:程序博客网 时间:2024/06/03 21:07
题意:
哥德巴赫猜想,一个偶数一定能化为两个质数的乘积。
思路:
练习了一下筛法求素数,不用写不成立的情况,因为目前还没有找出反例。
代码实现:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;const int MAX = 1000005;int N;int cnt;bool flag;int prime[MAX/2];bool is_prime[MAX];void sieve();int main(){ sieve(); while( scanf("%d",&N) != EOF ){ if( N == 0 ){ break; } flag = false; for( int i = 0; i < cnt; i++ ){ int a = prime[i]; int b = N-a; if( is_prime[b] == true ){ flag = true; printf("%d = %d + %d\n",N,a,b); break; } } } return 0;}void sieve(){ cnt = 0; for( int i = 0; i < MAX; i++ ){ is_prime[i] = true; } for( int i = 2; i < MAX; i++ ){ if( is_prime[i] == true ){ prime[cnt++] = i; for( int j = 2*i; j < MAX; j += i ){ is_prime[j] = false; } } } return ;}
0 0
- Poj_2262 Goldbach's Conjecture(筛法求素数)
- poj_2262 Goldbach's Conjecture
- Goldbach`s Conjecture 素数筛选
- poj 2262 Goldbach's Conjecture -- 筛法求素数打表
- HDOJ 1397 Goldbach's Conjecture [爱沙托散筛法求素数]
- POJ 2262 Goldbach's Conjecture(素数表)
- POJ 2909 Goldbach's Conjecture(素数表)
- PKU2262 Goldbach's Conjecture 数论-素数
- Goldbach's Conjecture map+素数表
- poj 2262 Goldbach's Conjecture 【素数筛】
- poj2262 Goldbach's Conjecture 素数的欧拉筛法
- poj 2262 Goldbach's Conjecture 素数筛
- Goldbach's Conjecture(数论--素数判断)
- poj 2262 Goldbach's Conjecture 素数 水题
- POJ 2262 Goldbach's Conjecture(素数相关)
- Goldbach`s Conjecture 【素数线性筛法】
- POJ 2262-Goldbach's Conjecture(素数筛)
- POJ2262 Goldbach's Conjecture(素数问题)
- Qt 之 使用 https:// 发送 HTTP请求
- hibernate--博客
- PAT:两个有序链表序列的合并(Java实现)
- 约瑟夫环
- QT之灰色头像(类似QQ离线头像)
- Poj_2262 Goldbach's Conjecture(筛法求素数)
- oracle数据库常用操作语句
- 看过的算法题(未亲自实现)
- Oracle数据库生成UUID
- LitePal无法使用自定义主键的临时解决方案
- Android从零开搞系列:自定义View(3)Canvas基本API+综合应用+开源分析
- 如何查看ubuntu下显卡驱动是否已经成功安装
- Spark性能调优
- Shiro身份验证Test