Ultraviolet A 10948-the primary problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.