Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
另类筛法#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<string> using namespace std; int h[1000010]; int main() { int i,j; for (i=5;i<1000;i+=4) { if (h[i]==0) { for (j=i;i*j<1000002;j+=4) { h[i*j]=h[i]+h[j]+1; } //cout<<i<<endl; } }//筛出来等于1的都是“素数”,0或者其他不是1的不是 for (i=25;i<1000002;i++) { h[i]=(h[i]==1)+h[i-1]; }//统计 while(scanf("%d",&i) && i) { printf("%d %d\n",i,h[i]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator