#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200001;
bool p[maxn]={0};
int prime[maxn];
int pnum=0;
void prime_make()
{
for(int i=2;i<maxn;i++)
{
if(p[i]==0)
{
prime[pnum++]=i;
for(int j=i+i;j<maxn;j=j+i)
{
p[j]=1;
}
}
}
//cout<<pnum<<endl;
}
int main()
{
prime_make();
int N,i=0,num=0;
cin>>N;
while(prime[i+1]<=N)//注意等于号,测试点2,读题不仔细
{
if((prime[i+1]-prime[i])==2)
{
num++;
//cout<<prime[i]<<" "<<prime[i+1]<<" "<<num<<endl;
}
i=i+1;
}
//cout<<pnum<<endl;
cout<<num<<endl;
return 0;
}
pat乙1007素数对猜想
最新推荐文章于 2022-11-12 16:48:44 发布