标签:prime int max main 数组 范围 oid ret for
#include <cstdio>
const int maxn = 10000001;
int prime[maxn]={0};
bool p[maxn] = {0};
int pnum =0;
void Find_prime(int n)
{
for(int i=2; i<=n; i++)
{
if(p[i] == false)
{
prime[pnum++] = i;
for(int j=i+i; j<= n; j+=i)
{
p[j] = true;
}
}
}
}
int main()
{
int N,count=0;//素数范围
scanf("%d",&N);
Find_prime(N);//找到N以内的所有素数存入数组prime
for(int i=0; i<pnum; i++){//遍历素数表
if(prime[i+1] - prime[i] == 2)
count++;
}
printf("%d",count);
return 0;
}
标签:prime int max main 数组 范围 oid ret for
原文地址:https://www.cnblogs.com/hebust/p/9813267.html