题目传送门:点击打开链接
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.
The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).
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.
5
2 2 3
6
3 2 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; }