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. servlet向浏览器输出信息

    package com.aaa.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebS ...

  2. Hadoop-2.2.0在Unbuntu ADM64中需要重新编译Native Lib

    通过:cat /etc/issue 查看当前系统版本: Ubuntu 12.04.3 通过:uname -ar 查看更想起信息: Linux ubuntu-236 3.8.0-29-generic # ...

  3. Linux删除重复内容命令uniq笔记

    针对文本文件,有时候我们需要删除其中重复的行.或者统计重复行的总次数,这时候可以采用Linux系统下的uniq命令实现相应的功能. 语法格式:uniq [-ic] 常用参数说明: -i 忽略大小写 - ...

  4. log日志模块得作用

    import logginglogger=logging.getLogger()logger.setLevel(logging.DEBUG)#控制台输出日志'''consle=logging.Stre ...

  5. 在 Linux 下判断系统当前是否开启了超线程

    转自: http://www.cnblogs.com/wjoyxt/p/4804293.html #lscpu Thread(s) per core: 2 Core(s) per socket: 6 ...

  6. vue.js层叠轮播

    最近写公司项目有涉及到轮播banner,一般的ui框架无法满足产品需求:所以自己写了一个层叠式轮播组件:现在分享给大家: 主要技术栈是vue.js ;javascript;jquery:确定实现思路因 ...

  7. UOJ #310 黎明前的巧克力 (FWT)

    题目传送门 题目大意:给你一个序列,定义一个子序列的权值表示子序列中元素的异或和,现在让你选出两个互不相交的子序列,求选出的这两个子序列权值相等的方案数,$n,a_{i}\leq 10^{6}$ 这是 ...

  8. [jzoj 5770]【2018提高组模拟A组8.6】可爱精灵宝贝 (区间dp)

    传送门 Description Branimirko是一个对可爱精灵宝贝十分痴迷的玩家.最近,他闲得没事组织了一场捉精灵的游戏.游戏在一条街道上举行,街道上一侧有一排房子,从左到右房子标号由1到n. ...

  9. python 图片滑动窗口

    METHOD #1: No smooth, just scaling. def pyramid(image, scale=1.5, minSize=(30, 30)): # yield the ori ...

  10. Python中对两种utf-8格式的理解

    1.python文件开头utf-8格式的理解 2.程序中读取文件时utf-8格式的理解 aa.py文件代码示例: #!/usr/bin/python # -*- coding:utf-8 -*- fr ...