| ||||||||||
| 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 | |||||||||
帮我看看怎么改能不TLE#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator