Codeforces Round #324 (Div. 2) D. Dima and Lisa (Goldbach conjecture + violence)

Source: Internet
Author: User

D. Dima and Lisa

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

More formally, your is given an odd numer n. Find a set of numbers pi (1≤ ik), such that

    1. 1 ≤ k ≤3
    2. P i is a prime

The numbers P I do not necessarily has to be distinct. It is guaranteed, at least one possible solution exists.

Input

The single line contains an odd number n (3≤ n <9).

Output

In the first line print k (1≤ k ≤ 3), showing how many numbers is in the representation y ou found.

In the second line print numbers pi in any order. If There is multiple possible solutions, you can print any of them.

Examplesinput
27
Output
3
5 11 11
Note

A Prime is an integer strictly larger than one, which is divisible A-by-one and by itself.

Test instructions is the sum of an odd n split into three or less primes.

According to Goldbach conjecture, any odd number greater than 7 can be written as a sum of three prime numbers. So we randomly find an odd number A as the first prime number, so that the n-a is even, according to the original Goldbach conjecture, any even greater than 2 can be written in the sum of two prime numbers, we can rest assured to find the remaining two primes. The distance between primes is only hundreds of, so you can actually be assured of violence (but I don't know). So I set the Miller-robin algorithm to detect the prime number (as a trial template).

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<cmath>#include<cstdlib>#include<ctime>using namespacestd;#definell Long LongConstll mod = 1e9 +7;Const intMAXN = 1e5 +Tenll Mod_mul (ll A, ll B, ll N) {ll res=0;  while(b) {if(b&1) Res = (res + a)%N; A= (A + a)%N; b>>=1; }    returnRes;} ll Mod_exp (ll A, ll B, ll N) {ll res=1;  while(b) {if(b&1) res =Mod_mul (Res, a, n); A=Mod_mul (A, A, n); b>>=1; }    returnRes;}BOOLMiller_rabin (ll N) {if(n = =2|| n = =3|| n = =5|| n = =7|| n = = One)return true; if(n = =1|| ! (n%2) || ! (n%3) || ! (n%5) || ! (n%7) || ! (n% One))return false;    ll x, pre, U; intI, j, k =0; U= N-1;  while(! (u&1) ) {k++; U >>=1; } srand ((ll) Time (0));  for(i =0; I < -; ++i) {x= rand ()% (n2) +2; if((x%n) = =0)Continue; X=mod_exp (x, u, n); Pre=x;  for(j =0; J < K; ++j) {x=Mod_mul (x, x, N); if(x = =1&& Pre! =1&& Pre! = N1)return false; Pre=x; }        if(X! =1)return false; }    return true;}intMain () {ll n;  while(~SCANF ("%i64d", &N)) {ll A; if(n = =3|| n = =5) printf ("1\n%i64d\n", N); Else {            if(n = =9) {printf ("2\n2 7\n");return 0;} if(n = =7) {printf ("1\n7\n");return 0;} A= N/3; ifA2==0) a++;  while(1) {a+=2; if(Miller_rabin (a)) Break; } puts ("3");            ll B, C;  for(b =3;; B + =2) {C= N-b-A; //cout << b << "<< C <<" "<< a << Endl;                if(Miller_rabin (b) &&Miller_rabin (c)) {                     Break; }} printf ("%i64d%i64d%i64d\n", A, b, c); }    }}

Codeforces Round #324 (Div. 2) D. Dima and Lisa (Goldbach conjecture + violence)

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.