Start: Jun, 28, 2019 08:42:00
2019杭州师范大学第一届程序设计竞赛新生赛
End: Jun, 28, 2019 11:42:00
Time elapsed:
Time remaining:

Problem_ID: F
Result: Accepted
Time: 463ms
Memory: 1116kB
In contest: 1276

#include<stdio.h>
#include<math.h>
int main(void)
{
	int i,count;
	int a;
	int t;
	int sushu[1000]={0};
	int j,limit,flag=1;
	for(i=1;i<=1000;++i)
	{	
		flag=1;
		if(i==1)flag=0;
		else if(i==2)flag=1;
		else if(i%2==0)flag=0;
		else
			{
				limit=sqrt(i)+1;
				for(j=3;j<=limit;j+=2)
				{
					if(i%j==0)
						{
							flag=0;
							break;
						}
				}
			}
		if(flag) sushu[i-1]=1;
		else sushu[i-1]=0;
	}
	scanf("%d",&t);
	while(t--)
	{
		count=0;
		scanf("%d",&a);
		for(i=1;i<a;++i)
		{
			if(sushu[i]==1)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}