Codeforces Round #388 (Div. 2) 749A Bachgold Problem

来源:互联网 发布:mac expect ssh 编辑:程序博客网 时间:2024/06/15 13:44

题目传送门:点击打开链接

A. Bachgold Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than1.

Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors —1 andk.

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

Output

The first line of the output contains a single integer k — maximum possible number of primes in representation.

The second line should contain k primes with their sum equal ton. You can print them in any order. If there are several optimal solution, print any of them.

Examples
Input
5
Output
22 3
Input
6
Output
32 2 2


思路:给你一个数n,问你最多能把n分成几个素数的和?输出素数的数量和这些素数。


思路:如果n是偶数的话。那就可以分成n/2个2

            如果n是奇数的话。那就可以分成((n-1)/2   -1)个2和一个3

#include<bits/stdc++.h>using namespace std;#define LL long long#define M(a)  memset(a,0,sizeof(a))int main(){    int n;    while(~scanf("%d",&n))    {        if(n==2)        {            printf("1\n");            printf("2\n");            continue;        }        if(n%2==0)        {            printf("%d\n",n/2);            for(int i=0;i<n/2;i++)            {                if(i==0)                {                    printf("2");                }                else                {                    printf(" 2");                }            }            printf("\n");        }        else        {            printf("%d\n",n/2);            for(int i=0;i<n/2-1;i++)            {                printf("2 ");            }            printf("3\n");        }    }    return 0;}




原创粉丝点击