PAT-乙级 1007 素数对猜想(C语言)

#include
#include

int  primeJudge(int num){
	int i;
	for (i = 2; i <= sqrt(num); i++){
		if (num % i == 0)
			break;
	}
	if (i > sqrt(num))
		return 1;
	else
		return 0;
}

int main() {
	int number = 0,sum=0;
	scanf("%d", &number);
	int i;
	for (i = 2; i <= number;i++) {
		if (primeJudge(i) == 1 && i <= number - 2 && primeJudge(i + 2) == 1)
					sum++;
	}
	printf("%d", sum);
	//system("pause");
	return 0;
}

你可能感兴趣的:(PAT-乙级(C语言))