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: 51ms
Memory: 1740kB
In contest: 1276

#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
const int maxn=1e4+5;
using namespace std;
int main()
{
    int a[maxn];
    a[1]=0;
    for(int i=2;i<=1005;++i)
    {
    	int f=1;
    	for(int j=2;j<=sqrt(i);++j)
    	{
    		if(i%j==0)
    		{
    			a[i]=a[i-1];
    			f=0;
    			break;
			}
		}
		if(f==1) a[i]=a[i-1]+1;
		//printf("%d\n",a[i-1]);
	}
	int n,t;
	cin>>t;
	while(t--)
	{
		scanf("%d",&n);
		printf("%d\n",a[n]-a[2]+1);
	}
}