POJ 2909 / ZOJ 1657 : Goldbach\'s Conjecture - 筛法打素数表
来源:互联网 发布:义乌淘宝网店摄影培训 编辑:程序博客网 时间:2024/05/29 03:29
和前面的POJ 2262类似
输出及细节处理略有不同
题意:
给出一个偶数,要求在这个偶数的范围内,有几对素数和是等于这个偶数的分析:
这次是验证哥德巴赫猜想的解有多少个,同样核心是打素数表
思路和POJ 2262差不多,筛法打素数表
注意素数对的不重复性!
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1000002;
bool b[N]={1,1,0};
int p[N/2],num=0;
void prime(){
int i,j,sq=(int)(sqrt(N*1.0));
for(i=1;i<sq;i++)
if(!b[i])
for(j=i*i;j<N;j+=i)
b[j]=1;
for(i=2;i<N;i++)
if(!b[i]) p[num++]=i;
}
int main(){
prime();
int n;
while(scanf("%d",&n)&&n){
int flag=0,count=0,i=0;
while(p[i]<n){
if(!b[n-p[i]]&&(n-p[i]==p[i])) count+=2;
else if(!b[n-p[i]]) count++;
i++;
}
printf("%d\n",count/2);
}
return 0;
}
0 0
- POJ 2909 / ZOJ 1657 : Goldbach\'s Conjecture - 筛法打素数表
- POJ 2262/ ZOJ 1951:Goldbach\'s Conjecture - 筛法打素数表
- POJ 2909 Goldbach's Conjecture(素数表)
- POJ 2262 Goldbach's Conjecture(素数表)
- zoj 1657 || poj 2262 Goldbach's Conjecture
- zoj 1657 Goldbach's Conjecture
- ZOJ 1951 Goldbach's Conjecture(素数打表)
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
- POJ 2262 Goldbach's Conjecture(素数表分解质数)
- poj 2262 Goldbach's Conjecture -- 筛法求素数打表
- POJ 2262 Goldbach's Conjecture 素数打表
- poj 2262 Goldbach's Conjecture 【素数筛】
- poj 2262 Goldbach's Conjecture 素数筛
- poj 2262 Goldbach's Conjecture 素数 水题
- POJ 2262 Goldbach's Conjecture(素数相关)
- POJ 2262-Goldbach's Conjecture(素数筛)
- POJ 2262 Goldbach's Conjecture 素数筛选
- POJ 2262 Goldbach's Conjecture(素数)
- POJ 2142 : The Balance-解不定方程,一元线性同余
- POJ 1305:Fermat vs. Pythagoras - 勾股定理/毕达哥拉斯三元组
- POJ 1320:Street Numbers——佩尔方程
- POJ 2262/ ZOJ 1951:Goldbach\'s Conjecture - 筛法打素数表
- 2015年10大web预测
- POJ 2909 / ZOJ 1657 : Goldbach\'s Conjecture - 筛法打素数表
- hibernate里createSQLQuery
- POJ 2773:Happy 2006 - 第k大与n互素的数
- POJ 1674 : Sorting by Swapping - 置换群
- POJ 3641 : Pseudoprime numbers - 米勒罗宾素数测试
- POJ 2407 : Relatives - 欧拉函数
- POJ 1284 : Primitive Roots - 欧拉函数,原根
- 黑马程序员java基础之io流中的其他流
- POJ 2478 : Farey Sequence - 欧拉函数