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

帮我看看怎么改能不TLE

Posted by swust20084856 at 2010-01-22 15:34:36 on Problem 3511
#include<stdio.h>
#include<math.h>
#define MAX 1000000
int prime[MAX]={0};
void p()
{
	int i,j;
	for(i=1;i<=MAX;i++)
		prime[i]=i;
	prime[1]=0;
	for(i=2;i<=sqrt((double)MAX);i++)
		for(j=i*i;j<=MAX;j+=i)
			prime[j]=0;
}
int main()
{
	int i,l,u,x,y,low,high;
	p();
	while(scanf("%d%d",&l,&u))
	{
		if(l==-1&&u==-1)
			break;
		x=y=0;
		low=l>2?l:1;
		high=u>2?u:1;
		for(i=low;i<=high;i++)
			if(prime[i]!=0)
			{
				x++;
				if(i%4==1)
					y++;
			}
			printf("%d %d %d %d\n",l,u,x,y);
	}
	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