题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2973
源代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#define maxn 3001000
using namespace std;
int prime[maxn],top=0;
int f[maxn]={0};
int ans[maxn]={0};
void getprime()
{
for(int i=2;i<maxn;i++)
{
if(!f[i])
{
prime[top++]=i;
if(i>=10&&(i-7)%3==0)
{
ans[(i-7)/3]=1;
}
}
for(int j=0;j<top&&i*prime[j]<maxn;j++)
{
f[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
for(int i=1;i<maxn;i++)
ans[i]+=ans[i-1];
}
int main()
{
getprime();
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("%d\n",ans[n]);
}
return 0;
}