poj 2909 Goldbach's Conjecture
2012-07-14 11:06
169 查看
素数水题:
View Code
View Code
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #include<cstring> #include<vector> using namespace std; int prime[10000],cnt=0; bool hash[100024]; void Prime( ) { int t = ( int )sqrt( 100000.0 ) + 1; memset( hash , 0 ,sizeof( hash ) ); for(int i = 3 ; i <= t ; i += 2 ) { if( !hash[i>>1] ) { int x = i<<1; for( int j = i * i; j <= 100001 ; j += x ) { hash[j>>1] = true; } } } cnt = 0; prime[cnt++] = 2; t = 100000/2; for( int i = 1; i <=t ; i ++ ) { if( !hash[i] ) { prime[cnt++] =i * 2 + 1; } } memset( hash , 0 ,sizeof( hash ) ); for( int i = 0 ; i < cnt; i ++ ) { hash[prime[i]] = true; } } int Solve( int num ) { int t = num/2,sum=0; for( int i = 0 ;i < cnt ;i ++ ) { if( prime[i] > t ) break; else { if( hash[num-prime[i]] ) { sum ++; } } } return sum; } int main( ) { Prime(); int num; while( scanf( "%d",&num ),num ) { printf( "%d\n",Solve( num ) ); } //system( "pause" ); return 0; }
相关文章推荐
- poj 2909(哥德巴赫猜想)
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
- poj 2909 Goldbach's Conjecture
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
- 筛素数——POJ 2909 Goldbach's Conjecture
- poj-2909-哥德巴赫猜想
- poj 2909
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
- poj 2909 哥德巴赫猜想
- POJ 2909 Goldbach's Conjecture (求x=p1+p2)
- POJ 2909 哥德巴赫猜想
- POJ 2909 Goldbach's Conjecture
- poj2909 欧拉素数筛选
- Cpp环境 【poj 2940 】【Uva11054】【Vijos2909】Wine Trading in Gergovia 格尔高维亚的肮脏红酒交易
- poj2909 || poj2262
- POJ-2909-Goldbach's Conjecture
- POJ2909_Goldbach's Conjecture【素数判断】【水题】
- POJ 2909 Goldbach's Conjecture(简单题)
- poj 2909 Goldbach's Conjecture
- POJ 2909 && HDU 1397 Goldbach's Conjecture(数论)