1007. 素数对猜想 (20)

来源:互联网 发布:同花顺龙虎榜数据 编辑:程序博客网 时间:2024/06/05 11:56

题目:http://www.patest.cn/contests/pat-b-practise/1007

代码:

#include <stdio.h>#include <math.h>int main(){  int n,i,k,j;  int sushu_before=2,sushu_after;  int sushu_num=0;  scanf("%d",&n);  for (i=3;i<=n;i++)  {    k = 1;    for (j=2;j<=(int)sqrt(i*1.0);j++)    {      if (i%j == 0)      {        k  = 0;        break;      }    }    if (k==1)    {      sushu_after = i;      if (sushu_after-sushu_before == 2)        sushu_num++;      sushu_before = sushu_after;    }  }  printf("%d",sushu_num);  return 0;}
0 0
原创粉丝点击