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 <cmath> using namespace std; int main(void) { unsigned int H; unsigned long i,j,index; unsigned int count; int *a=new int[1000002]; for(i=1;i<1000002;i++)a[i]=1; for(i=5;i<1000002;i+=4){ for(j=5,index=i*j;index<1000002,j<(1000002/i)+1;j+=4) { index=i*j; a[index]=0; } } while(1){ cin>>H; if(H ==0) break; count=0; for(i=5;i<=H;i+=4){ if(a[i]) count++; } cout<<H<<" "<<count<<endl; } delete[]a; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator