#include <iostream>
#include <cmath>
using namespace std;
bool sushu(int n)
{
if (n <= 3) {
return n > 1;
}
int b=sqrt(n);
for (int i = 2; i <=b; i++) {
if(n % i == 0) {
return false;
}
}
return true;
}
int main()
{
int N;
int num=0;
cin>>N;
int su[100000];
int j=0;
for(int i=2;i<=N;i++)
{
if(sushu(i)==true)
{
su[j]=i;
j++;
}
}
for(int i=0;i<j-1;i++)
{
if(su[i+1]-su[i]==2)
num++;
}
cout<<num;
return 0;
}
//重点在素数优化,可参考以下csdn文章:
https://blog.csdn.net/afei__/article/details/80638460?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159981038319725264609657%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=159981038319725264609657&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v3~pc_rank_v2-4-80638460.first_rank_ecpm_v3_pc_rank_v2&utm_term=%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E6%98%AF%E5%90%A6%E4%B8%BA%E7%B4%A0%E6%95%B0&spm=1018.2118.3001.4187
网友评论