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. 揭开jQuery的面纱

    简单地说,jQuery是一个优秀的JavaScript类库,也就是使用JavaScript面向对象的性质编写的一个JavaScript类的集合.jQuery究竟能为我们提供哪些功能呢?简单地说可以从七 ...

  2. Python中字典的相关操作

    1. Python类似于Java中的哈希表,只是两种语言表示的方式是不一样的,Python中的字典定义如下: 在Python中是一种可变的容器模型,它是通过一组键(key)值(value)对组成,这种 ...

  3. Java8新特性-接口中的静态方法与默认方法

    今天上午在读<Effective Java>时,有这样一句话:”接口中“不能有静态方法,于是联想起面试时老是被问接口相关的东西,决定总结一下,谁知道这一总结,就发现了自己知识的一大漏洞.  ...

  4. CF1168B Good Triple 性质分析_好题

    题意翻译 给出01串s,求数对[l,r]个数,使得能找到至少一对[x,k],使1<=x,k<=|s|且l<=x<x+2k<=r且s[x]=s[x+k]=s[x+2k] 题 ...

  5. 【剑指Offer】8、跳台阶

      题目描述:   一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果).   解题思路:   首先考虑最简单的情况,如果只有1级台阶, ...

  6. JS 常用语法

    通常,通过 JavaScript,您需要操作 HTML 元素. 1.通过 id 找到 HTML 元素 2.通过标签名找到 HTML 元素 3.通过类名找到 HTML 元素 提示:通过类名查找 HTML ...

  7. MAC下redis的安装和配置

    1.下载 打开官网:https://redis.io/ 选择下载你要的版本压缩包 2.安装 打开终端,cd - 将下载的压缩包拷贝到local目录下:sudo cp Downloads/redis-4 ...

  8. [luogu2624 HNOI2008]明明的烦恼 (prufer+高精)

    传送门 Solution 根据prufer序列做的题,具体可以看这里 还知道了一种避免高精除的方法quq Code #include <cmath> #include <cstdio ...

  9. java 定时器任务模板

    1.该定时任务是基于web.xml的监听机制 listener 来实现的 建立监听类: NFDFlightDataTaskListener.java import javax.servlet.Serv ...

  10. python网络编程系列

    计算机基础 网络基础 套接字 socket模块 TCP协议和UDP协议 struct 模块简介 struct 模块解决 TCP黏包问题 socket 客户端的认证 socketserver模块初识 客 ...