PAT甲級C語言.1007. 素數對猜想

#include<stdio.h>
#include<math.h>
int main()
{
	int i,j,k,temp,n=0;
	int s=2;
	scanf("%d",&k);
	if(k==1) return 0;
	else
		for(i=2;i<=k;i++)
		{
			temp=sqrt(i);
			for(j=2;j<=temp;++j)
				if(i%j==0) break;
			if(j>=temp+1)
			{
				if((i-s)==2)
					n++;
				s=i;
			}
		}
		printf("%d",n);
		return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章