素数对猜想 (20)
1 #include <iostream> 2 using namespace std; 3 4 bool isprime(int n){ 5 if (n <= 1) return false; 6 for (int i = 2; i*i <= n; i++) 7 if (n%i == 0) 8 return false; 9 return true; 10 } 11 12 int main(){ 13 int n, sum = 0, lastprime = 2; 14 cin >> n; 15 for (int i = 1; i <= n; i++){ 16 if (isprime(i)){ 17 if (i - lastprime == 2) sum++; 18 lastprime = i; 19 } 20 } 21 cout << sum; 22 return 0; 23 }