Codeforces Round #324 (Div. 2) D

D. Dima and Lisa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that

  1. 1 ≤ k ≤ 3
  2. pi is a prime

The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input

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

Output

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

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

Examples
Input
27
Output
3
5 11 11
Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.

题意:

  1. 1 ≤ k ≤ 3
  2. pi is a prime
  3.        输出这n个数

题解:

      n为奇数    所有的素数 除了2  都是奇数   奇数+奇数=偶数   奇数+偶数=奇数

     1.若n为素数  则输出n

     2.若n-2为素数  则输出 2 n-2

     3. 其余的暴力 定第一个数为3  找到满足条件的  i  n-i-3

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<stack>
 6 #include<cmath>
 7 #define ll __int64 
 8 #define pi acos(-1.0)
 9 #define mod 1000000007
10 using namespace std;
11 int n;
12 bool fun(int exm)
13 {
14     if(exm<=1)
15     return false; 
16     for(int i=2;i*i<=exm;i++)
17     {
18         if(exm%i==0)
19         return false;
20     }
21     return true;
22 }
23 int main()
24 {
25     scanf("%d",&n);
26     if(fun(n))
27     {
28         cout<<"1"<<endl<<n<<endl;
29         return 0;
30     }
31     if(fun(n-2))
32     {
33         cout<<"2"<<endl<<"2 "<<n-2<<endl;
34         return 0;
35     }
36     for(int i=3;i<=n-3;i++)
37     {
38         if(fun(i)&&fun(n-3-i))
39           {
40               cout<<"3"<<endl<<"3 "<<i<<" "<<n-3-i<<endl;
41               return 0;
42           }
43     }
44     return 0;
45 }
原文地址:https://www.cnblogs.com/hsd-/p/5550854.html