F - Dima and Lisa

Posted acgoto

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了F - Dima and Lisa相关的知识,希望对你有一定的参考价值。

Problem description

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
  3. 技术分享图片

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~3个素数,暴力即过!

哥德巴赫猜想:随便取某一个奇数,比如77,可以把它写成三个素数之和,即77=53+17+7;再任取一个奇数,比如461,可以表示成461=449+7+5,也是三个素数之和,461还可以写成257+199+5,仍然是三个素数之和。例子多了,即发现“任何大于5的奇数都是三个素数之和。”

AC代码(31ms):

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 bool isprime(int x){
 4     if(x<=1)return false;
 5     for(int i=2;i*i<=x;++i)
 6         if(x%i==0)return false;
 7     return true;
 8 }
 9 int main(){
10     int n;cin>>n;bool flag=false;
11     if(isprime(n))cout<<"1
"<<n<<endl;//如果本身是素数,直接输出即可
12     else{
13         for(int i=3;i<=n;i+=2){//从3开始按奇数来枚举
14             if(isprime(i)){
15                 int tmp=n-i;
16                 if(isprime(tmp)){cout<<"2
"<<i<< <<tmp<<endl;break;}
17                 for(int j=3;j<=n;j+=2)//从3开始按奇数来枚举
18                     if(isprime(j) && isprime(tmp-j)){cout<<"3
"<<i<< <<j<< <<(tmp-j)<<endl;flag=true;break;}
19                 if(flag)break;
20             }
21         }
22     }
23     return 0;
24 }

 


以上是关于F - Dima and Lisa的主要内容,如果未能解决你的问题,请参考以下文章

Codefroces 366 C Dima and Salad(dp)

Little Dima and Equation

Codeforces 374 C Inna and Dima (DFS)

Codefroces 366 D Dima and Trap Graph (最短路)

Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

Dima and Magic Guitar CodeForces - 366E