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: 453ms
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==1)
		flag=0;
	else if(n==2)
		flag=1;
	else if(n%2==0)
		flag=0;
	else{
		for(int i=3;i<limit;i++){
			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=2;i<1100;i++){
		if(isPrime(i)==1)
			a[i]=1;
	}
	//for(int i=3;i<=1000;i++)
	//	cout<<i<<':'<<a[i]<<endl;
	while(T--){
		int ans=0;
		int n;
		scanf("%d",&n);
		for(int i=2;i<=n;i++){
			if(a[i]==1)
				ans++;
		}
		printf("%d\n",ans);
	}                                                       
	return 0;
}