| ||||||||||
| 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 | |||||||||
why TLE?#include<iostream>
using namespace std;
#define M 1000001
int main()
{
bool prime[M];
int i,j;
for(i=0;i<M;i++)
prime[i]=true;
prime[0]=prime[1]=false;
for(i=2;i<M;i++)
{
if(prime[i])
{
for(j=2*i;j<M;j+=i)
prime[j]=false;
}
}
int L,U;
while(cin>>L>>U && !(L==-1 && U==-1))
{
int primenum=0,total=0;
if(U<=0)
{
i=U+1;
}
else if(L>=0) i=L;
else i=0;
for(;i<=U;i++)
{
if(prime[i]) { primenum++; if((i-1)%4==0 || i==2) total++;}
}
cout<<L<<" "<<U<<" "<<primenum<<" "<<total<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator