Learn how to filter prime numbers in 1-N. Note that all prime numbers except 2 must be odd.
This question is related to the Golden Bach conjecture.
# Include <iostream> # include <cmath> using namespace STD; int array [1000000] = {0}; int main () {// The difficulty lies in how to filter prime numbers within 1-most efficiently, it is easy to cause timeout or hyperspace. // learn the prime number embedding method from this question. // first, remove all the even numbers greater than 2. // CIN and cout are slower than printf, this will cause refor (INT I = 4; I <1000000; I + = 2) {array [I] = 1;} For (INT I = 3; I <SQRT (1000000 + 0.0); I + = 2) {If (! Array [I]) {int T = I * I; int T = I; array [T] = 1; // remove the number of rows while (T <1000000) {T + = 2; t = I * t; // remove all I + multiples, I + 4x, and so on. array [T] = 1 ;}}} int N; while (scanf ("% d", & N), n) {for (INT I = 3; I <= n/2; I ++) {If (array [I] = 0 & array [n-I] = 0) {printf ("% d = % d + % d/N", n, i, n-I); break ;}}
} Return 0 ;}