| ||||||||||
| 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;
struct array{
bool disp;
unsigned int value;
};
int main(void)
{
unsigned int H;
unsigned long i,j,index;
unsigned int count;
struct array *a=new struct array[1000002];
for(i=5;i<1000002;i+=4){
a[i].value=0;
a[i].disp=false;
}
for(i=5;i<1001;i+=4){
for(j=5,index=i*j;index<1000002,j<(1000002/i)+1;j+=4)
{
index=i*j;
if(a[i].value==0 && !a[i].disp)
a[index].value=1;
else{
a[index].value=0;
a[index].disp=true;
}
}
}
while(1){
cin>>H;
if(H ==0)
break;
count=0;
for(i=5;i<=H;i+=4){
if(a[i].value)
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