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: 65ms
Memory: 1712kB
In contest: 1276

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 50;
int main()
{
	int p[1005], sum[1005];
	p[1] = 0;
	p[2] = 1;
	for(int i=3;i<=1000;i++)
	{
		int flag = 1;
		for(int j = 2;j*j<=i;j++)
		{
			if(i % j == 0)flag = 0;
		}
		if(!flag) p[i] = 0;
		else p[i] = 1;
	}
	sum[2] = 1;
	for(int i=3;i<=1000;i++)
	{
		sum[i] = sum[i-1] + p[i];
	}
	int t;
	scanf("%d", &t);
	while(t--)
	{
		int n;
		scanf("%d", &n);
		printf("%d\n", sum[n]);
	}
	return 0;
}