标签:ret str sizeof cstring ref 筛法 prime pac color
https://vjudge.net/problem/UVA-11105
筛法
#include<cstdio> #include<cstring> #define N 1000002 using namespace std; int v[N],f[N/4+2]; int main() { memset(v,-1,sizeof(v)); for(int i=5;i<N;i+=4) for(int j=5;i*j<N;j+=4) { if(v[i]==-1 && v[j]==-1) v[i*j]=1; else v[i*j]=0; } int m=N/4,s=0; for(int i=1;i<m;i++) { if(v[i*4+1]==1) s++; f[i]=s; } int n; while(scanf("%d",&n)!=EOF) { if(!n) return 0; printf("%d %d\n",n,f[n-1>>2]); } }
UVA 11105 Semi-prime H-numbers
标签:ret str sizeof cstring ref 筛法 prime pac color
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7413730.html