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: 476ms
Memory: 1744kB
In contest: 1276

#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int isPrime(int n){
	int flag=1;
	int limit=sqrt(1.0*n)+1;
	if(n%2==0)
		flag=0;
	else{
		for(int i=3;i<limit;i+=2){
			if(n%i==0){
				flag=0;
				break;
			}
		}
	}
	return flag;
}
const int maxn=1100;
int a[maxn]={0};
int main(){
	int T;
	scanf("%d",&T);
	for(int i=3;i<1100;i++){
		if(isPrime(i)==1)
			a[i]=1;
	}
	while(T--){
		int ans=1;
		int n;
		scanf("%d",&n);
		for(int i=3;i<=n;i++){
			if(a[i]==1)
				ans++;
		}
		printf("%d\n",ans);
	}                                                       
	return 0;
}