线性删减
#include<iostream>
#define max_num 100005
using namespace std;
int flag_prime[max_num];
int prime[max_num/3], ff[max_num/3];
int len=0;
int main()
{
int i,j, n;
for(i=2;i<max_num;i++)
{
if(flag_prime[i] == 0)
{
prime[len]=i;
if(len != 0)
{
if(prime[len] - prime[len-1] == 2)
ff[len] = ff[len-1] + 1;
else
ff[len] = ff[len-1];
}
len++;
}
for(j=0;j<len && i*prime[j]<max_num;j++)
{
flag_prime[i*prime[j]]=1;
if(i%prime[j] == 0)
break;
}
}
while(scanf("%d", &n) != EOF && n >= 0)
{
for( i=0; i < n; i++)
{
if(prime[i] > n)
{
printf("%d\n", ff[i-1]);break;
}
}
}
return 0;
}