素数对猜想

C的语法都忘的差不多了,提交了好几次,最后才通过,先在devc++上跑了几次,才粘上去的

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int isPrime(int i)
{
 int flag=0,j=2;
 for(j;j<=sqrt(i);j++)//判断素数的方法,如果不开方的话,用最大的N就会超时,我第一次就是这样错的
 {
  if(i%j==0)  
  {
   flag++;
  }
  else continue;
  
 }
 if(flag==0)
 return i;
 else return 0;
}
int main(int argc, char *argv[]) {
 int number,temp,temp1,count,i;
 count=0;
 temp=1;
 temp1=2;
 scanf("%d",&number);
 
 for(i=2;i<=number;i++)
 {
   if(isPrime(i)!=0)
   {
    temp=isPrime(i);
   }
   else continue;
 int a;
 a=temp-temp1;
 if(a==2)
  {
   count++;
  }
  temp1=temp;
 
 }
 printf("%d",count);
 system("pause");
 return 0;
}

posted @ 2019-01-23 15:09  拎着红杯子的黄鸭子  Views(116)  Comments(0Edit  收藏  举报