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. $\sum_{i=1}^k p_i = n $

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.

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的奇数都是三个素数之和。”当然此题只是要求可以拆分成1~3个素数,并不要求一定是3个素数,譬如461本身就是素数,则此时直接输出1\n461即可。

AC代码(31ms):

 #include<bits/stdc++.h>
using namespace std;
bool isprime(int x){
if(x<=)return false;
for(int i=;i*i<=x;++i)
if(x%i==)return false;
return true;
}
int main(){
int n;cin>>n;bool flag=false;
if(isprime(n))cout<<"1\n"<<n<<endl;//如果本身是素数,直接输出即可
else{
for(int i=;i<=n;i+=){//从3开始按奇数来枚举
if(isprime(i)){
int tmp=n-i;
if(isprime(tmp)){cout<<"2\n"<<i<<' '<<tmp<<endl;break;}
for(int j=;j<=n;j+=)//从3开始按奇数来枚举
if(isprime(j) && isprime(tmp-j)){cout<<"3\n"<<i<<' '<<j<<' '<<(tmp-j)<<endl;flag=true;break;}
if(flag)break;
}
}
}
return ;
}

F - Dima and Lisa(哥德巴赫猜想)的更多相关文章

  1. Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  2. Codeforces Round #324 (Div. 2) Dima and Lisa 哥德巴赫猜想

    原题链接:http://codeforces.com/contest/584/problem/D 题意: 给你一个奇数,让你寻找三个以内素数,使得和为这个奇数. 题解: 这题嘛...瞎比搞搞就好,首先 ...

  3. 洛谷——P1579 哥德巴赫猜想(升级版)

    P1579 哥德巴赫猜想(升级版) 题目背景 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇数都可以表示成3个质数之和.质数是指除了1和本身之外没有其他约 ...

  4. Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)

                                                     D. Dima and Lisa Dima loves representing an odd num ...

  5. Java实现蓝桥杯算法提高 哥德巴赫猜想

    试题 算法提高 哥德巴赫猜想 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 根据所给函数(判断一个整数是否是素数),然后依托该函数,将输入N内的偶数(6-N),输出为两个素数之和( ...

  6. *CF2.D(哥德巴赫猜想)

    D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  7. C#实现哥德巴赫猜想

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Goet ...

  8. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  9. CF735D Taxes 哥德巴赫猜想\判定素数 \进一步猜想

    http://codeforces.com/problemset/problem/735/D 题意是..一个数n的贡献是它的最大的因子,这个因子不能等于它本身 然后呢..现在我们可以将n拆成任意个数的 ...

随机推荐

  1. 读书笔记「Python编程:从入门到实践」_10.文件和异常

    10.1 从文件中读取数据  10.1.1 读取整个文件 with open(~) as object: contents=object.read() with open('C:/Users/jou/ ...

  2. Java Web_过滤器

    过滤器分类: Servlet2.5: request:用户直接访问页面时,Web容器将会调用过滤器. forward:目标资源是通过RequestDispatcher的forward访问时,该过滤器将 ...

  3. Html-如何正确给table加边框

    一般来说,给表格加边框都会出现不同的问题,以下是给表格加边框后展现比较好的方式 <style> table,table tr th, table tr td { border:1px so ...

  4. TensorFlow实战笔记(17)---TFlearn

    目录: 分布式Estimator 自定义模型 建立自己的机器学习Estimator 调节RunConfig运行时的参数 Experiment和LearnRunner 深度学习Estimator 深度神 ...

  5. Ubuntu18.04 安装后应该做的事!!!

    一.WPS 进入WPS_Linux官网,下载对应的deb文件. WPS有官方的文件说明可供查看,WPS社区 WPS 的依赖关系,部分数学公式显示支持,都可以通过WPS社区查看 安装wps sudo d ...

  6. 09.正则表达式re-2.complie函数

    compile 函数用于编译正则表达式,生成一个 Pattern 对象,它的一般使用形式如下: import re # 将正则表达式编译成 Pattern 对象 pattern = re.compil ...

  7. 继续聊WPF——进度条

    ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值.   关键是它的控 ...

  8. 【2】数据采集 - urllib模块

    python2环境下关于urllib2的使用可以学习这篇文章.本文主要针对python3环境下使用urllib模块实现简单程序爬虫. 链接:https://www.jianshu.com/p/3183 ...

  9. 洛谷 P2587 BZOJ 1034 [ZJOI2008]泡泡堂

    题目描述 //不知道为什么BZOJ和洛谷都没有这幅图了,大牛们几年前的博客上都有这幅图的,把它贴上来吧 第XXXX届NOI期间,为了加强各省选手之间的交流,组委会决定组织一场省际电子竞技大赛,每一个省 ...

  10. eclipse快捷键深入理解

    1.Eclipse 中的重构功能使其成为了一个现代的 Java 集成开发环境 (IDE),而不再是一个普通的文本编辑器.使用重构,您可以轻松更改您的代码,而不必担心对别处造成破坏. 2.Eclipse ...