Question: Give You A number N, find two prime numbers so that the sum of these two prime numbers is N, and the interpolation is largest.
Analysis: number theory, greedy.
First, use the screening method to obtain the prime number in the first 1000000;
Then, query in order, and the first group finds the solution.
Note: Top 1000 of targets
# Include <iostream> # include <cstdlib> # include <cstdio> using namespace STD; int visit [1000000] = {0}; int prime [1000000] = {0 }; int main () {int COUNT = 0; visit [0] = visit [1] = 1; for (INT I = 2; I <1000000; ++ I) if (! Visit [I]) {Prime [count ++] = I; for (Int J = I <1; j <1000000; j + = I) visit [J] = 1;} int N; while (CIN> N & N) {int flag = 0; For (INT I = 0; I <count; ++ I) {If (prime [I] <1)> N) break; If (! Visit [n-prime [I]) {flag = prime [I]; break;} If (FLAG) printf ("% d: \ n % d + % d \ n ", N, flag, N-flag); else printf (" % d: \ NNo way! \ N ", n);} return 0 ;}
Ultraviolet A 10948-the primary problem