Result: Accepted
Time: 465ms
Memory: 1744kB
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<cmath>
#include<cctype>
#include<algorithm>
using namespace std;
int a[1005] = {0};
void mmm(int a[], int x) {
int i, j;
a[2] = 1;
a[3] = 1;
a[5] = 1;
for(i = 2; i <= x; i++) {
int flag = 0;
for(j = 2; j <= sqrt(double(i)) + 1; j++) {
if(j == i / 2 + 1)
a[i] = 1;
if(i % j == 0){
flag = 1;
break;
}
}
if(flag == 0)
a[i] = 1;
}
}
int main(){
mmm(a, 1000);
int t;
scanf("%d", &t);
int n, i, j;
while(t--) {
scanf("%d", &n);
int count = 0;
for(i = 2; i <= n; i++) {
if(a[i] == 1)
count++;
}
printf("%d", count);
if(t != 0)
printf("\n");
}
return 0;
}