Codeforces Round #388 (Div. 2) - A

 

题目链接:http://codeforces.com/contest/749/problem/A

题意:给定一个数n,求把n分解成尽量多的素数相加。输入素数个数和具体方案。

思路:因为要尽量多的素数,所以当n为奇数时用(n/2)-1个素数2还有一个素数3. 当n为偶数时用(n/2)个素数2

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
int main(){
//#ifdef kirito
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    int start = clock();
    int n;
    while (scanf("%d", &n) != EOF){
        int cnt = 0;
        if (n % 2 == 0){
            printf("%d\n", n / 2);
            for (int i = 0; i < n / 2; i++){
                printf("2");
                printf(i == (n / 2) - 1 ? "\n" : " ");
            }
        }
        else{
            printf("%d\n", n / 2);
            for (int i = 0; i < n / 2; i++){
                printf(i == (n / 2) - 1 ? "3" : "2");
                printf(i == (n / 2) - 1 ? "\n" : " ");
            }
        }
    }
//#ifdef LOCAL_TIME
//    cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
    return 0;
}

 

posted @ 2016-12-22 14:12  キリト  阅读(193)  评论(0编辑  收藏  举报