Pay special attention to this question: time limit per test: 0.5 sec. Memory
Limit per test: 4096 kb, so pay special attention to constructing a prime number table and marking an array.
# Include <cstdio> # include <cstring> # include <iostream> using namespace STD; int isprime (int n) {for (INT I = 2; I * I <= N; I ++) if (N % I = 0) return 0; return 1 ;}int main () {int COUNT = 0; int N; // while (scanf ("% d", & N )! = EOF) // in the question, the input has only one number, so the write Will PE scanf ("% d", & N); {bool prime [n + 1]; // use int to exceed the memory. // For (INT I = 0; I <= N & I <2; I ++) // prime [I] = false; /* For (INT I = 2; I <= N; I ++) {Prime [I] = false; If (isprime (I )) // this way, the construction of the prime number table will time out prime [I] = true;} */For (INT I = 0; I <= N; I ++) {if (I = 0 | I = 1) prime [I] = false; else Prime [I] = true ;}for (INT I = 2; I * I <= N; I ++) {for (Int J = I; I * j <= N; j ++) {Prime [I * j] = false ;}// learn this method to construct a prime number table // For (INT I = 0; I <= N; I ++) // If (prime [I]) // cout <I <Endl; For (INT I = 0; I <n; I ++) {If (2 + I <= N & prime [I] & prime [I + 2]) Count ++;} cout <count; If (count) for (INT I = 0; I <n; I ++) {If (2 + I <= N & prime [I] & prime [I + 2]) cout <"" <"2" <"" <I;} cout <Endl;} return 0 ;}