1007 素数对猜想 (20)
链接:点我
思路同1013
#include <stdio.h> #include <math.h> bool isPrime(int val) { if (val <= 1) return false; int sqr = (int) sqrt(1.0 * val); for (int j = 2; j <= sqr; j++) { if (val % j == 0) return false; } return true; } int main (void) { int val = 0; int cout = 0; int i = 0; scanf ("%d", &val); for (i = 3; i +2 <= val; i += 2) { if ((isPrime(i) == true) && (isPrime(i+2) == true)) { cout ++; } } printf ("%d", cout); }