Codeforces 584D Dima and Lisa

Source: Internet
Author: User

Dima loves representing a odd number as the sum of multiple primes, and Lisa loves it when there are at most three . Help them to represent the given number as the sum of at most than three.

More formally, your are given a odd numer n. Find a set of Numbers Pi (1≤i≤k), such this 1≤k≤3 pi is a prime

The numbers pi don't necessarily have to be distinct. It is guaranteed this at least one possible solution exists.
Input

The single line contains a odd number n (3≤n < 109).
Output

In the I-line print K (1≤k≤3), showing how many numbers are to the representation you.

In the second line print numbers pi into any order. If There are multiple possible solutions, you can print any of the them.
Sample Test (s)
Input

27

Output

3
5 11 11

Note

A Prime is A integer strictly larger than one, is divisible to by one and by itself. title: To divide an odd number into 1 to 3 prime numbers. Solving Ideas: violence.

 #include <cstdio> #include <cstring> #include <algorithm> #include <

Cmath> #include <cstdlib> using namespace std;

typedef long Long LL; 
    BOOL IsPrime (int num) {for (int i = 2; I <= sqrt (num), i++) {if (num% i = = 0) return 0;
return 1;
    int main () {int n;
    scanf ("%d", &n);   
    if (IsPrime (n)) {printf ("1\n%d\n", N); 
    else if (IsPrime (n-2)) {printf ("2\n%d 2\n", n-2);   
    else if (IsPrime (n-4)) {printf ("3\n%d 2 2\n", n-4);  
            else {for (int i = 3; I <= n; i = 2) {int m = n-i;
                    for (int j = 3; J < m; j = 2) {if (IsPrime (m-j) && IsPrime (j) && IsPrime (i)) {   
                    printf ("3\n%d%d%d\n", M-j, J, i);
                return 0;
return 0; }

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.