这题坑了我,原因是题目数据问题1000000告诉我100 OTL
附代码
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 bool prime[1100000] = {0}; 7 8 void getlist(int maxint) { 9 prime[1] = 1; 10 for(int i = 2 ; i <= maxint/2 ; ++i) { 11 if(!prime[i]) 12 for(int j = i<<1 ; j <= maxint ; j += i) 13 prime[j] = 1; 14 } 15 } 16 17 int main() { 18 ios::sync_with_stdio(false); 19 int n; 20 cin >> n; 21 getlist(n); 22 int total = 0; 23 for(int i = 3 ; i <= n ; ++i) { 24 if(!prime[i] && !prime[i-2]) 25 ++total; 26 if(!prime[i] && !prime[i-1]) 27 ++total; 28 } 29 cout << total << endl; 30 return 0; 31 }