让我们定义d n 为:d n =p n+1 −p n ,其中p i 是第i个素数。显然有d 1 =1,且对于n>1有d n 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。 现给定任意正整数N(<10 5 ),请计算不超过N的满足猜想的素数对的个数。
输入格式:
输入在一行给出正整数N。
输出格式:
在一行中输出不超过N的满足猜想的素数对的个数。
输入样例:
20
输出样例:
4
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int judge(int i){
int n=2;
if(i==1)return 0;
while(n<=sqrt(i)) {
if(i%n==0)return 0;
n++;
}
return 1;
}
int main(int argc, char *argv[])
{
int n,a[101010];
int i,j,t=0,count=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
if(judge(i)==1) {
a[t]=i;
//printf("%d ",a[t]);
t++;
}
}
for(i=0;i<t;i++){
if(a