Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why TLE?

Posted by dart at 2008-02-29 15:19:30 on Problem 3511
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator