1
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,j,k=0,m=0,arr[100000];
cin >> n;
//找素数
for (int i = 2; i <= n; i++)
{
for (j = 2; j <= (int)sqrt(i); j++)
{
if (i % j == 0)
break;
}
if (j > sqrt(i))
arr[k++] =i ;
}
//判断并记录素数对,并输出个数
for (int i = 0; i < k - 1; i++)
{
if (arr[i + 1] - arr[i] == 2)
m++;
}
cout << m;
return 0;
}
2
#include<iostream>
#include<math.h>
using namespace std;
bool findsushu(int a)
{
for (int i = 2; pow(i,2)<= a; i++)
{
if (a % i == 0)
return false;
}
return true;
}
int main()
{
int n, numb = 0;
cin >> n;
for (int i = 4; i <= n; i++)
{
if (findsushu(i - 2) && findsushu(i))
numb++;
}
cout << numb;
return 0;
}